Skip to content

Commit

Permalink
feat: add support call api
Browse files Browse the repository at this point in the history
  • Loading branch information
RenauxLeaInsee committed Sep 26, 2024
1 parent 2914707 commit e0a0640
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 45 deletions.
36 changes: 16 additions & 20 deletions src/components/surveyHomepage/AuthenticatedSupport.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useFetchQueryPortail } from "hooks/useFetchQuery";
import { useFetchMutationPortail, useFetchQueryPortail } from "hooks/useFetchQuery";
import { useForm } from "hooks/useForm";
import { useState } from "react";
import { supportSchema } from "types/schemas";
import { Loading } from "./Loading";
import { SupportForm } from "./SupportForm";
Expand All @@ -16,30 +15,27 @@ export const AuthenticatedSupport = ({

const { data: questioningUrlData, isLoading } = useFetchQueryPortail("/questionnaires-url");

const [isSuccess, setIsSuccess] = useState(false);
const { mutateAsync, isSuccess } = useFetchMutationPortail("/e-mail", "post");

if (!questioningUrlData || isLoading) {
return <Loading />;
}

// TODO: call api
const onSubmit = handleSubmit(async data => {
const formattedData = {
auth: true,
idec: data.idec,
idue: questioningUrlData[0].idUE,
questioningId: questioningId,
mailaddress: data.mailaddress,
message: data.message,
name: `${data.firstName} ${data.lastName}`,
phonenumber: data.phonenumber,
survey: surveyId,
mailobjet: data.mailObjet,
};
console.log("formattedData", formattedData);

// TODO: use mutation isSucess instead
setIsSuccess(true);
await mutateAsync({
body: {
auth: true,
idec: data.idec,
idue: questioningUrlData[0].idUE,
questioningId: questioningId ? parseInt(questioningId) : undefined,
mailaddress: data.mailaddress,
message: data.message,
name: `${data.firstName} ${data.lastName}`,
phonenumber: data.phonenumber,
survey: surveyId,
mailobjet: data.mailObjet,
},
});
});

return (
Expand Down
35 changes: 16 additions & 19 deletions src/components/surveyHomepage/OfflineSupport.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import { useForm } from "hooks/useForm";
import { useState } from "react";
import { supportSchema } from "types/schemas";
import { SupportForm } from "./SupportForm";
import { useFetchMutationPortail } from "hooks/useFetchQuery";

export const OfflineSupport = ({ surveyId }: { surveyId: string }) => {
const { register, handleSubmit, errors } = useForm(supportSchema);

const [isSuccess, setIsSuccess] = useState(false);
const { mutateAsync, isSuccess } = useFetchMutationPortail("/e-mail", "post");

// TODO: call api
const onSubmit = handleSubmit(async data => {
const formattedData = {
auth: false,
idec: data.idec,
idue: undefined,
questioningId: undefined,
mailaddress: data.mailaddress,
message: data.message,
name: `${data.firstName} ${data.lastName}`,
phonenumber: data.phonenumber,
survey: surveyId,
mailobjet: data.mailObjet,
};
console.log("formattedData", formattedData);

// TODO: use mutation isSucess instead
setIsSuccess(true);
await mutateAsync({
body: {
auth: false,
idec: data.idec,
idue: undefined,
questioningId: undefined,
mailaddress: data.mailaddress,
message: data.message,
name: `${data.firstName} ${data.lastName}`,
phonenumber: data.phonenumber,
survey: surveyId,
mailobjet: data.mailObjet,
},
});
});

return (
Expand Down
7 changes: 1 addition & 6 deletions src/types/apiPortail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ export type APISchemas = {
name?: string;
phonenumber?: string;
survey?: string;
mailobjet?:
| "Affichage du questionnaire"
| "Comprehension du questionnaire"
| "Autre"
| "Perte d'identifiant"
| "Perte de mot de passe";
mailobjet?: string
};
MailAssistanceStatusDto: {
message?: string;
Expand Down

0 comments on commit e0a0640

Please sign in to comment.