From ff15c7cf95fadcf33f75d08474ef920097a95981 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 5 Apr 2024 10:32:25 +0200 Subject: [PATCH] :sparkles: handle change manage collaborators --- .../SubscriptionManageCollaborators/index.tsx | 151 +++++++++++------- 1 file changed, 90 insertions(+), 61 deletions(-) diff --git a/src/front/Components/Layouts/Subscription/Manage/SubscriptionManageCollaborators/index.tsx b/src/front/Components/Layouts/Subscription/Manage/SubscriptionManageCollaborators/index.tsx index ac418a9d..066e33f5 100644 --- a/src/front/Components/Layouts/Subscription/Manage/SubscriptionManageCollaborators/index.tsx +++ b/src/front/Components/Layouts/Subscription/Manage/SubscriptionManageCollaborators/index.tsx @@ -5,21 +5,97 @@ import Form from "@Front/Components/DesignSystem/Form"; import CheckBox from "@Front/Components/DesignSystem/CheckBox"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import { useCallback, useEffect, useState } from "react"; -import { Subscription } from "le-coffre-resources/dist/Admin"; +import User, { Subscription } from "le-coffre-resources/dist/Admin"; import JwtService from "@Front/Services/JwtService/JwtService"; import Subscriptions from "@Front/Api/LeCoffreApi/Admin/Subscriptions/Subscriptions"; export default function SubscriptionManageCollaborators() { const [subscription, setSubscription] = useState(null); + const [availableCollaborators, setAvailableCollaborators] = useState([ + { + created_at: new Date("2021-09-29T14:00:00.000Z"), + uid: "1", + idNot: "1", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + contact: { + civility: "M", + created_at: new Date("2021-09-29T14:00:00.000Z"), + email: "jean.dupont@gmail.com", + first_name: "Jean", + last_name: "Dupont", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + }, + }, + { + created_at: new Date("2021-09-29T14:00:00.000Z"), + uid: "2", + idNot: "1", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + contact: { + civility: "M", + created_at: new Date("2021-09-29T14:00:00.000Z"), + email: "jean.dupont@gmail.com", + first_name: "Jean", + last_name: "Dupont", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + }, + }, + + { + created_at: new Date("2021-09-29T14:00:00.000Z"), + uid: "3", + idNot: "1", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + contact: { + civility: "M", + created_at: new Date("2021-09-29T14:00:00.000Z"), + email: "jean.dupont@gmail.com", + first_name: "Jean", + last_name: "Dupont", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + }, + }, + { + created_at: new Date("2021-09-29T14:00:00.000Z"), + uid: "4", + idNot: "1", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + contact: { + civility: "M", + created_at: new Date("2021-09-29T14:00:00.000Z"), + email: "jean.dupont@gmail.com", + first_name: "Jean", + last_name: "Dupont", + updated_at: new Date("2021-09-29T14:00:00.000Z"), + }, + }, + ]); + const [selectedCollaborators, setSelectedCollaborators] = useState([]); const loadSubscription = useCallback(async () => { const jwt = JwtService.getInstance().decodeJwt(); const subscription = await Subscriptions.getInstance().get({ where: { office: { uid: jwt?.office_Id } } }); console.log(subscription); if (!subscription[0]) return; + subscription[0].seats?.forEach((seat) => setSelectedCollaborators((prev) => [...prev, seat.user.uid!])); setSubscription(subscription[0]); }, []); + const handleChange = useCallback( + (event: React.ChangeEvent) => { + if (!subscription) return; + const value = event.target.value; + if (selectedCollaborators.includes(value)) { + setSelectedCollaborators((prev) => prev.filter((collaborator) => collaborator !== value)); + } else { + if (selectedCollaborators.length <= subscription.nb_seats!) { + setSelectedCollaborators((prev) => [...prev, value]); + } + } + }, + [selectedCollaborators, subscription], + ); + useEffect(() => { loadSubscription(); }, [loadSubscription]); @@ -36,68 +112,21 @@ export default function SubscriptionManageCollaborators() {
- - - - - - - - + {availableCollaborators.map((collaborator) => ( + + ))}
- 7 collaborateurs sélectionnés + {selectedCollaborators.length} collaborateurs sélectionnés