✨ Connecting office roles
This commit is contained in:
parent
48cb8c6072
commit
37cfc25a71
67
src/front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts
Normal file
67
src/front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import { Role } from "le-coffre-resources/dist/Admin";
|
||||||
|
|
||||||
|
import BaseAdmin from "../BaseAdmin";
|
||||||
|
|
||||||
|
export type IGetRolesParams = {
|
||||||
|
where?: {};
|
||||||
|
include?: {};
|
||||||
|
select?: {};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type IPutRoleParams = {
|
||||||
|
rules: Role["rules"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class OfficeRoles extends BaseAdmin {
|
||||||
|
private static instance: OfficeRoles;
|
||||||
|
private readonly baseURl = this.namespaceUrl.concat("/office-roles");
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getInstance() {
|
||||||
|
if (!this.instance) {
|
||||||
|
return new OfficeRoles();
|
||||||
|
} else {
|
||||||
|
return this.instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async get(q?: IGetRolesParams): Promise<Role[]> {
|
||||||
|
const url = new URL(this.baseURl);
|
||||||
|
|
||||||
|
if (q) {
|
||||||
|
const query = { q };
|
||||||
|
Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await this.getRequest<Role[]>(url);
|
||||||
|
} catch (err) {
|
||||||
|
this.onError(err);
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getByUid(uid: string, q?: any): Promise<Role> {
|
||||||
|
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||||
|
if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||||
|
try {
|
||||||
|
return await this.getRequest<Role>(url);
|
||||||
|
} catch (err) {
|
||||||
|
this.onError(err);
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async put(uid: string, body: IPutRoleParams): Promise<Role> {
|
||||||
|
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||||
|
try {
|
||||||
|
return await this.putRequest<Role>(url, body);
|
||||||
|
} catch (err) {
|
||||||
|
this.onError(err);
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,10 +28,14 @@ export default class Roles extends BaseAdmin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get(q: IGetRolesParams): Promise<Role[]> {
|
public async get(q?: IGetRolesParams): Promise<Role[]> {
|
||||||
const url = new URL(this.baseURl);
|
const url = new URL(this.baseURl);
|
||||||
const query = { q };
|
|
||||||
Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
if (q) {
|
||||||
|
const query = { q };
|
||||||
|
Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.getRequest<Role[]>(url);
|
return await this.getRequest<Role[]>(url);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -17,6 +17,7 @@ export default function CollaboratorListContainer(props: IProps) {
|
|||||||
const [filteredUsers, setFilteredUsers] = useState<User[]>(props.collaborators);
|
const [filteredUsers, setFilteredUsers] = useState<User[]>(props.collaborators);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const { collaboratorUid } = router.query;
|
||||||
const filterUsers = useCallback(
|
const filterUsers = useCallback(
|
||||||
(input: string) => {
|
(input: string) => {
|
||||||
const filteredUsers = props.collaborators.filter((user) => {
|
const filteredUsers = props.collaborators.filter((user) => {
|
||||||
@ -51,7 +52,7 @@ export default function CollaboratorListContainer(props: IProps) {
|
|||||||
return {
|
return {
|
||||||
name: user.contact?.first_name + " " + user.contact?.last_name,
|
name: user.contact?.first_name + " " + user.contact?.last_name,
|
||||||
id: user.uid!,
|
id: user.uid!,
|
||||||
selected: false,
|
selected: user.uid === collaboratorUid,
|
||||||
};
|
};
|
||||||
})}
|
})}
|
||||||
onSelectedBlock={onSelectedBlock}
|
onSelectedBlock={onSelectedBlock}
|
||||||
|
@ -2,7 +2,7 @@ import ChevronIcon from "@Assets/Icons/chevron.svg";
|
|||||||
import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users";
|
import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users";
|
||||||
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||||
import CheckBox from "@Front/Components/DesignSystem/CheckBox";
|
import CheckBox from "@Front/Components/DesignSystem/CheckBox";
|
||||||
import SelectField from "@Front/Components/DesignSystem/Form/SelectField";
|
import SelectField, { IOption } from "@Front/Components/DesignSystem/Form/SelectField";
|
||||||
import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography";
|
import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography";
|
||||||
import DefaultCollaboratorDashboard from "@Front/Components/LayoutTemplates/DefaultCollaboratorDashboard";
|
import DefaultCollaboratorDashboard from "@Front/Components/LayoutTemplates/DefaultCollaboratorDashboard";
|
||||||
import User from "le-coffre-resources/dist/Notary";
|
import User from "le-coffre-resources/dist/Notary";
|
||||||
@ -12,6 +12,7 @@ import { useEffect, useState } from "react";
|
|||||||
|
|
||||||
import classes from "./classes.module.scss";
|
import classes from "./classes.module.scss";
|
||||||
import Module from "@Front/Config/Module";
|
import Module from "@Front/Config/Module";
|
||||||
|
import OfficeRoles from "@Front/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles";
|
||||||
|
|
||||||
type IProps = {};
|
type IProps = {};
|
||||||
export default function CollaboratorInformations(props: IProps) {
|
export default function CollaboratorInformations(props: IProps) {
|
||||||
@ -19,6 +20,7 @@ export default function CollaboratorInformations(props: IProps) {
|
|||||||
let { collaboratorUid } = router.query;
|
let { collaboratorUid } = router.query;
|
||||||
|
|
||||||
const [userSelected, setUserSelected] = useState<User | null>(null);
|
const [userSelected, setUserSelected] = useState<User | null>(null);
|
||||||
|
const [availableRoles, setAvailableRoles] = useState<IOption[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getUser() {
|
async function getUser() {
|
||||||
@ -26,16 +28,20 @@ export default function CollaboratorInformations(props: IProps) {
|
|||||||
const user = await Users.getInstance().getByUid(collaboratorUid as string, {
|
const user = await Users.getInstance().getByUid(collaboratorUid as string, {
|
||||||
q: {
|
q: {
|
||||||
contact: true,
|
contact: true,
|
||||||
|
office_role: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
|
|
||||||
|
const roles = await OfficeRoles.getInstance().get();
|
||||||
|
if (!roles) return;
|
||||||
|
setAvailableRoles(roles.map((role) => ({ value: role.uid, label: role.name })));
|
||||||
setUserSelected(user);
|
setUserSelected(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser();
|
getUser();
|
||||||
}, [collaboratorUid]);
|
}, [collaboratorUid]);
|
||||||
|
|
||||||
const mockedRole = { value: "1", label: "Clerc de notaire" };
|
|
||||||
return (
|
return (
|
||||||
<DefaultCollaboratorDashboard mobileBackText={"Liste des collaborateurs"}>
|
<DefaultCollaboratorDashboard mobileBackText={"Liste des collaborateurs"}>
|
||||||
<div className={classes["root"]}>
|
<div className={classes["root"]}>
|
||||||
@ -85,7 +91,15 @@ export default function CollaboratorInformations(props: IProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes["second-line"]}>
|
<div className={classes["second-line"]}>
|
||||||
<SelectField placeholder="Rôle" name="role" options={[mockedRole]} selectedOption={mockedRole} />
|
<SelectField
|
||||||
|
placeholder="Rôle"
|
||||||
|
name="role"
|
||||||
|
options={availableRoles}
|
||||||
|
selectedOption={{
|
||||||
|
value: userSelected?.office_role?.uid,
|
||||||
|
label: userSelected?.office_role?.name!,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes["third-line"]}>
|
<div className={classes["third-line"]}>
|
||||||
<CheckBox
|
<CheckBox
|
||||||
|
Loading…
x
Reference in New Issue
Block a user