Skip to content

Commit

Permalink
add SU address data in createContact dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
RenauxLeaInsee committed May 3, 2024
1 parent 99d7638 commit e9f3b5d
Show file tree
Hide file tree
Showing 11 changed files with 488 additions and 174 deletions.
63 changes: 23 additions & 40 deletions src/pages/CreateContactPage.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
import Stack from "@mui/material/Stack";
import { useForm } from "../hooks/useForm";
import { schema } from "../ui/Contact/ContactFormDialog";
import { useRef, useState } from "react";
import { useState } from "react";
import { Row } from "../ui/Row";
import Button from "@mui/material/Button";
import PersonAddAltOutlinedIcon from "@mui/icons-material/PersonAddAltOutlined";
import Typography from "@mui/material/Typography";
import { Step, StepLabel, Stepper, Divider, Card } from "@mui/material";
import { InformationsForm } from "../ui/Contact/CreateContact/InformationsForm";
import { RightsManagementForm } from "../ui/Contact/CreateContact/RightsManagementForm";
import { Breadcrumbs } from "../ui/Breadcrumbs";

// const steps = ["Informations du contact", "Adresse du contact", "Gestion des droits"];

const steps = ["Informations du contact", "Gestion des droits"];

export const CreateContactPage = () => {
const { register, control, errors } = useForm(schema);
const [activeStep, setActiveStep] = useState(0);
const [contactData, setContactData] = useState();

const data = useRef(new FormData());

const onSubmitStep = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const newData = new FormData(event.currentTarget);
console.log("new data", { newData });
for (let [name, value] of newData) {
data.current.append(name, value);
}
};
const [rights, setRights] = useState();

Check failure on line 17 in src/pages/CreateContactPage.tsx

View workflow job for this annotation

GitHub Actions / test_lint

'rights' is assigned a value but never used

const handleNext = () => {
setActiveStep(prevActiveStep => prevActiveStep + 1);
Expand All @@ -38,8 +24,15 @@ export const CreateContactPage = () => {
setActiveStep(prevActiveStep => prevActiveStep - 1);
};

const handleSubmitStep = async (event: React.FormEvent<HTMLFormElement>) => {
onSubmitStep(event);
const handleSubmitStep = async (data: any) => {
if (activeStep === 0) {
setContactData(data);
}

if (activeStep === 1) {
setRights(data);
}

handleNext();
};

Expand All @@ -50,7 +43,7 @@ export const CreateContactPage = () => {
];

return (
<Stack>
<Stack pb={5}>
<Divider variant="fullWidth" />
<Stack>
<Row spacing={1} px={6} py={4} bgcolor={"white"} justifyContent={"space-between"}>
Expand All @@ -72,27 +65,17 @@ export const CreateContactPage = () => {
</Row>
<Breadcrumbs items={breadcrumbs} />
<Card sx={{ mt: 5, px: 6, py: 3, maxWidth: "1160px", alignSelf: "center" }} elevation={2}>
<form action="#" onSubmit={handleSubmitStep}>
{activeStep === 0 && (
<InformationsForm errors={errors} register={register} control={control} />
)}
{/* {activeStep === 1 && <AddressForm errors={errors} register={register} />} */}
{activeStep === 1 && <RightsManagementForm />}
<Row p={4} justifyContent={"flex-end"}>
<Button
disabled={activeStep === 0}
variant={"outlined"}
onClick={handleBack}
sx={{ mr: 1 }}
>
Annuler
</Button>
{activeStep === 0 && (
<InformationsForm
handleSubmitStep={handleSubmitStep}
handleBack={handleBack}
contact={contactData}
/>
)}

<Button type="submit" variant="contained">
Suivant
</Button>
</Row>
</form>
{activeStep === 1 && (
<RightsManagementForm handleSubmitStep={handleSubmitStep} handleBack={handleBack} />
)}
</Card>
</Stack>
</Stack>
Expand Down
22 changes: 21 additions & 1 deletion src/pages/Search/SearchContacts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CardActionArea, CircularProgress, Stack } from "@mui/material";
import { Button, CardActionArea, CircularProgress, Stack } from "@mui/material";
import { Row } from "../../ui/Row";
import { useInfiniteFetchQuery } from "../../hooks/useFetchQuery.ts";
import ToggleButtonGroup from "@mui/material/ToggleButtonGroup";
Expand All @@ -10,6 +10,7 @@ import { type APIResponse } from "../../types/api.ts";
import { type ItemOf } from "../../types/utils.ts";
import Card from "@mui/material/Card";
import { Link } from "react-router-dom";
import { Link as CustomLink } from "../../ui/Link";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { TextWithLeftIcon } from "../../ui/TextWithLeftIcon.tsx";
Expand All @@ -19,6 +20,7 @@ import EmailIcon from "@mui/icons-material/Email";
import DesktopWindowsOutlinedIcon from "@mui/icons-material/DesktopWindowsOutlined";
import { useSearchFilterParams } from "../../hooks/useSearchFilter.ts";
import { ContactCardTitle } from "../../ui/SurveyUnit/SurveyUnitContacts.tsx";
import EditIcon from "@mui/icons-material/Edit";

const endpoint = "/api/contacts/search" as const;
type Item = ItemOf<Required<APIResponse<typeof endpoint, "get">>["content"]>;
Expand Down Expand Up @@ -67,6 +69,24 @@ export const SearchContacts = () => {
))}
{hasNextPage && <VisibilitySpy onVisible={fetchNextPage} />}
</CardGrid>
<Button
sx={{
position: "fixed",
bottom: "48px",
right: "32px",
borderRadius: 24,
typography: "titleSmall",
fontWeight: "500",
}}
size="large"
fullWidth={false}
variant="contained"
endIcon={<EditIcon />}
>
<CustomLink to={"/contacts/createContact"} color="inherit" underline="none">
Créer un nouveau contact
</CustomLink>
</Button>
</Stack>
);
};
Expand Down
Loading

0 comments on commit e9f3b5d

Please sign in to comment.