Page select folders unmocked
This commit is contained in:
parent
0967c142dd
commit
489cdd9685
38
src/front/Api/Auth/franceConnect/Customer.ts
Normal file
38
src/front/Api/Auth/franceConnect/Customer.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import BaseApiService from "@Front/Api/BaseApiService";
|
||||
|
||||
export default class Customer extends BaseApiService {
|
||||
private static instance: Customer;
|
||||
private readonly baseURl = this.getBaseUrl().concat("/france-connect/customer");
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static getInstance() {
|
||||
if (!this.instance) {
|
||||
return new Customer();
|
||||
} else {
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
|
||||
public async login(email: string) {
|
||||
const url = new URL(this.baseURl.concat("/login/").concat(email));
|
||||
try {
|
||||
return await this.postRequest(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
public async refreshToken(refreshToken: string): Promise<{ accessToken: string }> {
|
||||
const url = new URL(this.baseURl.concat("/refresh-token"));
|
||||
try {
|
||||
return await this.postRequest(url, {}, refreshToken);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { File } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { File } from "le-coffre-resources/dist/Customer";
|
||||
import BaseCustomer from "../BaseCustomer";
|
||||
|
||||
// TODO Type get query params -> Where + inclue + orderby
|
||||
|
57
src/front/Api/LeCoffreApi/Customer/Folders/Folders.ts
Normal file
57
src/front/Api/LeCoffreApi/Customer/Folders/Folders.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import { type OfficeFolder } from "le-coffre-resources/dist/Customer";
|
||||
|
||||
import BaseCustomer from "../BaseCustomer";
|
||||
|
||||
// TODO Type get query params -> Where + inclue + orderby
|
||||
export interface IGetFoldersParams {
|
||||
q?: {
|
||||
select?: {};
|
||||
where?: {};
|
||||
include?: {};
|
||||
};
|
||||
}
|
||||
|
||||
export default class Folders extends BaseCustomer {
|
||||
private static instance: Folders;
|
||||
private readonly baseURl = this.namespaceUrl.concat("/folders");
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static getInstance() {
|
||||
if (!this.instance) {
|
||||
return new this();
|
||||
} else {
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all folders
|
||||
*/
|
||||
public async get(q: IGetFoldersParams): Promise<OfficeFolder[]> {
|
||||
const url = new URL(this.baseURl);
|
||||
Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||
try {
|
||||
return await this.getRequest<OfficeFolder[]>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a folder by uid
|
||||
*/
|
||||
public async getByUid(uid: string, q?: any): Promise<OfficeFolder> {
|
||||
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<OfficeFolder>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ import LandingImage from "./landing-connect.jpeg";
|
||||
|
||||
export default function Login() {
|
||||
const router = useRouter();
|
||||
|
||||
const redirectUserOnConnection = useCallback(() => {
|
||||
async function getUser() {
|
||||
try {
|
||||
@ -28,6 +29,21 @@ export default function Login() {
|
||||
|
||||
getUser();
|
||||
}, [router]);
|
||||
|
||||
const redirectCustomerOnConnection = useCallback(() => {
|
||||
async function getUser() {
|
||||
try {
|
||||
await UserStore.instance.connectCustomer("antoine.bernard@outlook.com");
|
||||
await JwtService.getInstance().checkJwt();
|
||||
router.push(Module.getInstance().get().modules.pages.Folder.pages.Select.props.path);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
getUser();
|
||||
}, [router]);
|
||||
|
||||
return (
|
||||
<DefaultDoubleSidePage title={"Login"} image={LandingImage}>
|
||||
<div className={classes["root"]}>
|
||||
@ -38,6 +54,9 @@ export default function Login() {
|
||||
<Button onClick={redirectUserOnConnection} icon={idNoteLogo} iconposition={"left"}>
|
||||
S'identifier avec ID.not
|
||||
</Button>
|
||||
<Button onClick={redirectCustomerOnConnection} icon={idNoteLogo} iconposition={"left"}>
|
||||
S'identifier en tant que customer
|
||||
</Button>
|
||||
<Typography typo={ITypo.P_18}>
|
||||
<div className={classes["forget-password"]}>Vous n'arrivez pas à vous connecter ?</div>
|
||||
</Typography>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Folders from "@Front/Api/LeCoffreApi/SuperAdmin/Folders/Folders";
|
||||
import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders";
|
||||
import BlockList, { IBlock } from "@Front/Components/DesignSystem/BlockList";
|
||||
import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography";
|
||||
import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage";
|
||||
@ -8,6 +8,7 @@ import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import LandingImage from "../Login/landing-connect.jpeg";
|
||||
import classes from "./classes.module.scss";
|
||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
||||
|
||||
export default function SelectFolder() {
|
||||
const [folders, setFolders] = useState<OfficeFolder[]>([]);
|
||||
@ -15,8 +16,23 @@ export default function SelectFolder() {
|
||||
|
||||
useEffect(() => {
|
||||
async function getFolders() {
|
||||
const folders = await Folders.getInstance().get({});
|
||||
setFolders(folders.slice(0, 3));
|
||||
const jwt = JwtService.getInstance().decodeJwt();
|
||||
if (!jwt) return;
|
||||
console.log(jwt);
|
||||
|
||||
const folders = await Folders.getInstance().get({
|
||||
q: {
|
||||
where: {
|
||||
customers: {
|
||||
some: {
|
||||
uid: jwt.userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
setFolders(folders);
|
||||
console.log(folders);
|
||||
}
|
||||
|
||||
getFolders();
|
||||
|
@ -38,7 +38,9 @@ export default class JwtService {
|
||||
*/
|
||||
public async checkJwt() {
|
||||
const decodedToken = this.decodeJwt();
|
||||
if(!decodedToken) return;
|
||||
console.log(decodedToken);
|
||||
|
||||
if (!decodedToken) return;
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import User from "@Front/Api/Auth/IdNot/User";
|
||||
import Customer from "@Front/Api/Auth/franceConnect/Customer";
|
||||
import CookieService from "@Front/Services/CookieService/CookieService";
|
||||
import EventEmitter from "@Front/Services/EventEmitter";
|
||||
|
||||
@ -33,6 +34,23 @@ export default class UserStore {
|
||||
return true;
|
||||
}
|
||||
|
||||
public async connectCustomer(email: string) {
|
||||
try {
|
||||
//call connection function
|
||||
const customer: any = await Customer.getInstance().login(email);
|
||||
|
||||
//Save tokens in cookies
|
||||
CookieService.getInstance().setCookie("leCoffreAccessToken", customer.accessToken);
|
||||
CookieService.getInstance().setCookie("leCoffreRefreshToken", customer.refreshToken);
|
||||
|
||||
this.event.emit("connection", this.accessToken);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public async disconnect() {
|
||||
try {
|
||||
//Remove tokens from cookies
|
||||
|
Loading…
x
Reference in New Issue
Block a user