From 19f95b0ab74ca86b2c344e3b2d1a59b436ce152a Mon Sep 17 00:00:00 2001 From: Mihoub Date: Wed, 9 Oct 2024 14:59:13 +0200 Subject: [PATCH 1/3] feat(contacts): add new form for remove user et change user name --- client/src/components/contact-form/index.tsx | 48 ++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/client/src/components/contact-form/index.tsx b/client/src/components/contact-form/index.tsx index a8aee9f..7cf9c72 100644 --- a/client/src/components/contact-form/index.tsx +++ b/client/src/components/contact-form/index.tsx @@ -4,12 +4,14 @@ import { Notice, TextArea, TextInput, + Select, + SelectOption, useDSFRConfig, } from "@dataesr/dsfr-plus"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import useForm from "../../hooks/useForm"; import { useMutation } from "@tanstack/react-query"; -import { useNavigate } from "react-router-dom"; +import { useNavigate, useLocation } from "react-router-dom"; import { createIntl, RawIntlProvider } from "react-intl"; import { postHeadersTicketOffice } from "../../config/api"; @@ -61,8 +63,9 @@ export default function ContactForm({ objectId, objectType }: Props) { const { locale } = useDSFRConfig(); const intl = createIntl({ locale, messages: messages[locale] }); const navigate = useNavigate(); - const api = objectId && objectType ? "contribute" : "contacts"; + const location = useLocation(); const [thanks, setThanks] = useState(false); + const [api, setApi] = useState("contacts"); const { isPending, isError, mutate } = useMutation({ mutationFn: async (data: FormState) => { let payload = { ...data }; @@ -98,6 +101,18 @@ export default function ContactForm({ objectId, objectType }: Props) { validate ); + const handleApiChange = (key: any) => { + if (key === "contact") setApi("contacts"); + else if (key === "remove") setApi("remove-user"); + else if (key === "nameChange") setApi("update-user-data"); + }; + + useEffect(() => { + if (location.pathname.includes("bugs")) { + setApi("contribute"); + } + }, [location]); + if (thanks) { return ( @@ -142,6 +157,33 @@ export default function ContactForm({ objectId, objectType }: Props) { mutate(form); }} > + {!location.pathname.includes("bugs") && ( + + )} + updateForm({ name: e.target.value })} From 4caee5cdfcc994da0c68477c594127bb2521f9c6 Mon Sep 17 00:00:00 2001 From: Mihoub Date: Wed, 9 Oct 2024 18:02:12 +0200 Subject: [PATCH 2/3] fix(contact-form): add organizzation and fonction in extra body --- client/src/components/contact-form/index.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/src/components/contact-form/index.tsx b/client/src/components/contact-form/index.tsx index 7cf9c72..00214a6 100644 --- a/client/src/components/contact-form/index.tsx +++ b/client/src/components/contact-form/index.tsx @@ -68,14 +68,23 @@ export default function ContactForm({ objectId, objectType }: Props) { const [api, setApi] = useState("contacts"); const { isPending, isError, mutate } = useMutation({ mutationFn: async (data: FormState) => { - let payload = { ...data }; + let payload: any = { ...data }; + + if (data.organization || data.fonction) { + payload.extra = { + ...(data.organization && { organisation: data.organization }), + ...(data.fonction && { fonction: data.fonction }), + }; + } if (api === "contacts") { payload = { ...payload, fromApplication: "scanr" }; } + if (api === "contribute") { payload = { ...payload, objectId, objectType }; } + const resp = await fetch(`/ticket/api/${api}`, { method: "POST", body: JSON.stringify(payload), @@ -96,6 +105,7 @@ export default function ContactForm({ objectId, objectType }: Props) { console.error("error", e); }, }); + const { form, updateForm, errors } = useForm( {}, validate From 3a00afc1acb1e8286ade6ccd2e6e082aab73d199 Mon Sep 17 00:00:00 2001 From: Mihoub Date: Wed, 9 Oct 2024 18:09:02 +0200 Subject: [PATCH 3/3] fix(contact-form): delete useless item from payload --- client/src/components/contact-form/index.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/src/components/contact-form/index.tsx b/client/src/components/contact-form/index.tsx index 00214a6..5767819 100644 --- a/client/src/components/contact-form/index.tsx +++ b/client/src/components/contact-form/index.tsx @@ -75,6 +75,9 @@ export default function ContactForm({ objectId, objectType }: Props) { ...(data.organization && { organisation: data.organization }), ...(data.fonction && { fonction: data.fonction }), }; + + delete payload.organization; + delete payload.fonction; } if (api === "contacts") {