mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-12 11:46:40 +00:00
fetch allUsers in ProjectController, combined in project viewmodel,fixed user model checkboxes
This commit is contained in:
parent
d692d10e72
commit
2023ba8ccd
7 changed files with 54 additions and 33 deletions
10
client/package-lock.json
generated
10
client/package-lock.json
generated
|
|
@ -1626,6 +1626,11 @@
|
||||||
"@types/testing-library__dom": "*"
|
"@types/testing-library__dom": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/underscore": {
|
||||||
|
"version": "1.9.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.9.4.tgz",
|
||||||
|
"integrity": "sha512-CjHWEMECc2/UxOZh0kpiz3lEyX2Px3rQS9HzD20lxMvx571ivOBQKeLnqEjxUY0BMgp6WJWo/pQLRBwMW5v4WQ=="
|
||||||
|
},
|
||||||
"@types/yargs": {
|
"@types/yargs": {
|
||||||
"version": "13.0.8",
|
"version": "13.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.8.tgz",
|
||||||
|
|
@ -12539,6 +12544,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz",
|
||||||
"integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw=="
|
"integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw=="
|
||||||
},
|
},
|
||||||
|
"underscore": {
|
||||||
|
"version": "1.9.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.2.tgz",
|
||||||
|
"integrity": "sha512-D39qtimx0c1fI3ya1Lnhk3E9nONswSKhnffBI0gME9C99fYOkNi04xs8K6pePLhvl1frbDemkaBQ5ikWllR2HQ=="
|
||||||
|
},
|
||||||
"unicode-canonical-property-names-ecmascript": {
|
"unicode-canonical-property-names-ecmascript": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,14 @@
|
||||||
"@types/react": "^16.9.19",
|
"@types/react": "^16.9.19",
|
||||||
"@types/react-dom": "^16.9.5",
|
"@types/react-dom": "^16.9.5",
|
||||||
"@types/react-router-dom": "^5.1.3",
|
"@types/react-router-dom": "^5.1.3",
|
||||||
|
"@types/underscore": "^1.9.4",
|
||||||
"history": "^4.10.1",
|
"history": "^4.10.1",
|
||||||
"react": "^16.12.0",
|
"react": "^16.12.0",
|
||||||
"react-dom": "^16.12.0",
|
"react-dom": "^16.12.0",
|
||||||
"react-router-dom": "^5.1.2",
|
"react-router-dom": "^5.1.2",
|
||||||
"react-scripts": "3.3.1",
|
"react-scripts": "3.3.1",
|
||||||
"typescript": "^3.7.5"
|
"typescript": "^3.7.5",
|
||||||
|
"underscore": "^1.9.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,19 @@ export default class ProjectVM {
|
||||||
public value: number;
|
public value: number;
|
||||||
public tickets: Ticket[];
|
public tickets: Ticket[];
|
||||||
public users: User[];
|
public users: User[];
|
||||||
|
public allUsers: User[];
|
||||||
public ticketsTotalCount: number;
|
public ticketsTotalCount: number;
|
||||||
public ticketsDone: number;
|
public ticketsDone: number;
|
||||||
public remainingDays: number;
|
public remainingDays: number;
|
||||||
public files: AppFile[];
|
public files: AppFile[];
|
||||||
public activities: Activity[];
|
public activities: Activity[];
|
||||||
|
|
||||||
public constructor(project: Project) {
|
public constructor(project: Project, allUsers: User[]) {
|
||||||
this.id = project.id;
|
this.id = project.id;
|
||||||
this.title = project.title;
|
this.title = project.title;
|
||||||
this.description = project.description;
|
this.description = project.description;
|
||||||
this.users = project.users;
|
this.users = project.users;
|
||||||
|
this.allUsers = allUsers;
|
||||||
this.value = project.progression;
|
this.value = project.progression;
|
||||||
this.tickets = project.tickets;
|
this.tickets = project.tickets;
|
||||||
this.ticketsTotalCount =
|
this.ticketsTotalCount =
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,22 @@ import { get, put } from "../utils/http";
|
||||||
import { Constants } from "../utils/Constants";
|
import { Constants } from "../utils/Constants";
|
||||||
import { UsersModalEntry } from "./UsersModalEntry";
|
import { UsersModalEntry } from "./UsersModalEntry";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
import _ from "underscore";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
handleClose: () => void;
|
handleClose: () => void;
|
||||||
users: User[];
|
users: User[];
|
||||||
|
allUsers: User[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UsersModal: FC<IProps> = ({ show, handleClose, users }) => {
|
export const UsersModal: FC<IProps> = ({
|
||||||
|
show,
|
||||||
|
handleClose,
|
||||||
|
users,
|
||||||
|
allUsers
|
||||||
|
}) => {
|
||||||
const [filterText, setFilterText] = useState<string>("");
|
const [filterText, setFilterText] = useState<string>("");
|
||||||
const [allUsers, setAllUsers] = useState<User[]>([]);
|
|
||||||
const [members, setMembers] = useState<User[]>(users);
|
const [members, setMembers] = useState<User[]>(users);
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
|
|
@ -39,29 +45,6 @@ export const UsersModal: FC<IProps> = ({ show, handleClose, users }) => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function httpGet(): Promise<void> {
|
|
||||||
try {
|
|
||||||
const response: HttpResponse<User> = await get<User>(
|
|
||||||
`${Constants.usersURI}`
|
|
||||||
);
|
|
||||||
if (response.parsedBody !== undefined) {
|
|
||||||
setAllUsers((response.parsedBody as unknown) as User[]);
|
|
||||||
}
|
|
||||||
} catch (ex) {
|
|
||||||
// setHasError(true);
|
|
||||||
// setError(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// if (id !== undefined) {
|
|
||||||
httpGet();
|
|
||||||
// } else {
|
|
||||||
// setHasError(true);
|
|
||||||
// setError("Bad Request");
|
|
||||||
// }
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal show={show} handleClose={handleClose}>
|
<Modal show={show} handleClose={handleClose}>
|
||||||
<div className="row valign-wrapper blue">
|
<div className="row valign-wrapper blue">
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import React, { FC } from "react";
|
import React, { FC } from "react";
|
||||||
import { User } from "../types/User";
|
import { User } from "../types/User";
|
||||||
|
import _ from "underscore";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
setMembers: React.Dispatch<React.SetStateAction<User[]>>;
|
setMembers: React.Dispatch<React.SetStateAction<User[]>>;
|
||||||
|
|
@ -8,6 +9,10 @@ interface IProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UsersModalEntry: FC<IProps> = ({ user, setMembers, members }) => {
|
export const UsersModalEntry: FC<IProps> = ({ user, setMembers, members }) => {
|
||||||
|
console.log(members);
|
||||||
|
const match: (id: string) => boolean = (id: string) => {
|
||||||
|
return Boolean(members.find(m => m.id === id));
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<label htmlFor={user.id}>
|
<label htmlFor={user.id}>
|
||||||
|
|
@ -15,11 +20,11 @@ export const UsersModalEntry: FC<IProps> = ({ user, setMembers, members }) => {
|
||||||
id={user.id}
|
id={user.id}
|
||||||
name={user.fullName}
|
name={user.fullName}
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
defaultChecked={members.includes(user)}
|
defaultChecked={match(user.id)}
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
!members.includes(user)
|
!match(user.id)
|
||||||
? setMembers([...members, user])
|
? setMembers([...members, user])
|
||||||
: setMembers(members.filter(p => p !== user));
|
: setMembers(members.filter(p => p.id !== user.id));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span>
|
<span>
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,17 @@ import { HttpResponse } from "../types/HttpResponse";
|
||||||
import { Preloader } from "../components/Preloader";
|
import { Preloader } from "../components/Preloader";
|
||||||
import { Constants } from "../utils/Constants";
|
import { Constants } from "../utils/Constants";
|
||||||
import { get } from "../utils/http";
|
import { get } from "../utils/http";
|
||||||
|
import { User } from "../types/User";
|
||||||
|
|
||||||
export const ProjectController: FC = () => {
|
export const ProjectController: FC = () => {
|
||||||
const [project, setProject] = useState<Project>({} as Project);
|
const [project, setProject] = useState<Project>({} as Project);
|
||||||
|
const [allUsers, setAllUsers] = useState<User[]>([]);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [hasError, setHasError] = useState(false);
|
const [hasError, setHasError] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
async function httpGet(id: string): Promise<void> {
|
async function httpGetProjects(id: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const response: HttpResponse<Project> = await get<Project>(
|
const response: HttpResponse<Project> = await get<Project>(
|
||||||
`${Constants.projectsURI}/${id}`
|
`${Constants.projectsURI}/${id}`
|
||||||
|
|
@ -31,9 +33,24 @@ export const ProjectController: FC = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function httpGetAllUsers(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const response: HttpResponse<User> = await get<User>(
|
||||||
|
`${Constants.usersURI}`
|
||||||
|
);
|
||||||
|
if (response.parsedBody !== undefined) {
|
||||||
|
setAllUsers((response.parsedBody as unknown) as User[]);
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
// setHasError(true);
|
||||||
|
// setError(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (id !== undefined) {
|
if (id !== undefined) {
|
||||||
httpGet(id);
|
httpGetProjects(id);
|
||||||
|
httpGetAllUsers();
|
||||||
} else {
|
} else {
|
||||||
setHasError(true);
|
setHasError(true);
|
||||||
setError("Bad Request");
|
setError("Bad Request");
|
||||||
|
|
@ -43,6 +60,6 @@ export const ProjectController: FC = () => {
|
||||||
if (hasError) {
|
if (hasError) {
|
||||||
return <ErrorController error={error} />;
|
return <ErrorController error={error} />;
|
||||||
}
|
}
|
||||||
const viewModel = new ProjectVM(project);
|
const viewModel = new ProjectVM(project, allUsers);
|
||||||
return isLoading ? <Preloader /> : <ProjectPage viewModel={viewModel} />;
|
return isLoading ? <Preloader /> : <ProjectPage viewModel={viewModel} />;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ export const ProjectPage: FC<IProps> = ({ viewModel }) => {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
users,
|
users,
|
||||||
|
allUsers,
|
||||||
value,
|
value,
|
||||||
tickets,
|
tickets,
|
||||||
ticketsDone,
|
ticketsDone,
|
||||||
|
|
@ -43,6 +44,7 @@ export const ProjectPage: FC<IProps> = ({ viewModel }) => {
|
||||||
<UsersModal
|
<UsersModal
|
||||||
show={showModal}
|
show={showModal}
|
||||||
users={users}
|
users={users}
|
||||||
|
allUsers={allUsers}
|
||||||
handleClose={() => setShowModal(false)}
|
handleClose={() => setShowModal(false)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue