add office uid from cookies
This commit is contained in:
parent
755fc3cd3e
commit
ed436facbf
@ -21,6 +21,7 @@ import { ActionMeta, MultiValue } from "react-select";
|
||||
|
||||
import BasePage from "../../Base";
|
||||
import classes from "./classes.module.scss";
|
||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
||||
|
||||
type IFormValues = {
|
||||
folder_number: string;
|
||||
@ -233,16 +234,12 @@ class CreateFolderClass extends BasePage<IPropsClass, IState> {
|
||||
[key: string]: any;
|
||||
},
|
||||
) {
|
||||
const officeId = (JwtService.getInstance().decodeJwt())?.office_Id;
|
||||
console.log('form initializdd');
|
||||
const selectedDeedTypeUid: DeedType | undefined = this.state.deedTypes.find(
|
||||
(deedType) => deedType.uid === this.state.formValues.act_typ?.value,
|
||||
);
|
||||
|
||||
/**
|
||||
* MOCK DATA
|
||||
*/
|
||||
const usersMock = await Users.getInstance().get({ include: { office_membership: true } });
|
||||
const userMock = usersMock[0];
|
||||
|
||||
let stakeholders = this.state.collaborators;
|
||||
if (this.state.folder_access === "select_collaborators") {
|
||||
stakeholders = this.state.collaborators.filter((collaborator) => {
|
||||
@ -261,23 +258,27 @@ class CreateFolderClass extends BasePage<IPropsClass, IState> {
|
||||
}),
|
||||
}),
|
||||
office: Office.hydrate<Office>({
|
||||
uid: userMock?.office_membership?.uid,
|
||||
uid: officeId,
|
||||
}),
|
||||
customers: [],
|
||||
stakeholders
|
||||
});
|
||||
|
||||
console.log('form');
|
||||
|
||||
try {
|
||||
await officeFolderForm.validateOrReject?.({ groups: ["createFolder"], forbidUnknownValues: false });
|
||||
} catch (validationErrors) {
|
||||
this.setState({
|
||||
validationError: validationErrors as ValidationError[],
|
||||
});
|
||||
console.log('validation errros');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const newOfficeFolder = await Folders.getInstance().post(officeFolderForm);
|
||||
console.log('new office folder: ',newOfficeFolder)
|
||||
if (!newOfficeFolder) return;
|
||||
this.props.router.push(`/folders/${newOfficeFolder.uid}`);
|
||||
} catch (backError: any) {
|
||||
|
@ -26,15 +26,19 @@ export default class JwtService {
|
||||
return (this.instance ??= new this());
|
||||
}
|
||||
|
||||
public decodeJwt(): IUserJwtPayload | undefined {
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
if (!accessToken) return;
|
||||
return jwt_decode(accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : set a cookie with a name and a value that expire in 7 days
|
||||
* @throws {Error} If the name or the value is empty
|
||||
*/
|
||||
public async checkJwt() {
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
|
||||
if (!accessToken) return;
|
||||
const decodedToken: IUserJwtPayload = jwt_decode(accessToken);
|
||||
const decodedToken = this.decodeJwt();
|
||||
if(!decodedToken) return;
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user