-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modeles): ajout des autres références
- Loading branch information
Showing
12 changed files
with
210 additions
and
45 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
targets/frontend/src/components/forms/LegiReferences/FormLegiReferences.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Control } from "react-hook-form"; | ||
import { LegiReference } from "./type"; | ||
import { useContributionSearchLegiReferenceQuery } from "./legiReferencesSearch.query"; | ||
import { FormAutocompleteChips } from "../"; | ||
|
||
type Props = { | ||
name: string; | ||
control: Control<any>; | ||
disabled?: boolean; | ||
}; | ||
|
||
export const FormLegiReferences = ({ | ||
name, | ||
control, | ||
disabled = false, | ||
}: Props): React.ReactElement => { | ||
return ( | ||
<FormAutocompleteChips<LegiReference> | ||
isMultiple={true} | ||
label={`Références liées au code du travail`} | ||
color="success" | ||
name={name} | ||
disabled={disabled} | ||
control={control} | ||
fetcher={useContributionSearchLegiReferenceQuery} | ||
isEqual={(option, value) => | ||
value.legiArticle.id === option.legiArticle.id | ||
} | ||
getLabel={(item) => item.legiArticle.label} | ||
onClick={(item) => { | ||
const newWindow = window.open( | ||
`https://www.legifrance.gouv.fr/codes/article_lc/${item.legiArticle.id}`, | ||
"_blank", | ||
"noopener,noreferrer" | ||
); | ||
if (newWindow) newWindow.opener = null; | ||
}} | ||
/> | ||
); | ||
}; |
42 changes: 2 additions & 40 deletions
42
targets/frontend/src/components/forms/LegiReferences/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,2 @@ | ||
import { Control } from "react-hook-form"; | ||
import { LegiReference } from "./type"; | ||
import { useContributionSearchLegiReferenceQuery } from "./legiReferencesSearch.query"; | ||
import { FormAutocompleteChips } from "../"; | ||
|
||
type Props = { | ||
name: string; | ||
control: Control<any>; | ||
disabled?: boolean; | ||
}; | ||
|
||
export const FormLegiReferences = ({ | ||
name, | ||
control, | ||
disabled = false, | ||
}: Props): React.ReactElement => { | ||
return ( | ||
<FormAutocompleteChips<LegiReference> | ||
isMultiple={true} | ||
label={`Références liées au code du travail`} | ||
color="success" | ||
name={name} | ||
disabled={disabled} | ||
control={control} | ||
fetcher={useContributionSearchLegiReferenceQuery} | ||
isEqual={(option, value) => | ||
value.legiArticle.id === option.legiArticle.id | ||
} | ||
getLabel={(item) => item.legiArticle.label} | ||
onClick={(item) => { | ||
const newWindow = window.open( | ||
`https://www.legifrance.gouv.fr/codes/article_lc/${item.legiArticle.id}`, | ||
"_blank", | ||
"noopener,noreferrer" | ||
); | ||
if (newWindow) newWindow.opener = null; | ||
}} | ||
/> | ||
); | ||
}; | ||
export * from "./FormLegiReferences"; | ||
export * from "./type"; |
97 changes: 97 additions & 0 deletions
97
targets/frontend/src/components/forms/OtherReferences/FormOtherReferences.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { Button, IconButton, Stack } from "@mui/material"; | ||
import DeleteIcon from "@mui/icons-material/Delete"; | ||
import AddIcon from "@mui/icons-material/Add"; | ||
import React from "react"; | ||
import { TitleBox } from "../TitleBox"; | ||
import { FormTextField } from ".."; | ||
import { Control, useFieldArray } from "react-hook-form"; | ||
|
||
type OtherProps = { | ||
index: number; | ||
name: string; | ||
control: Control<any>; | ||
onDelete: () => void; | ||
disabled: boolean; | ||
}; | ||
|
||
const OtherReferenceLine = ({ | ||
index, | ||
name, | ||
control, | ||
onDelete, | ||
disabled, | ||
}: OtherProps): React.ReactElement => { | ||
return ( | ||
<Stack direction="row" spacing={2}> | ||
<FormTextField | ||
name={`${name}.${index}.label`} | ||
label="Nom" | ||
control={control} | ||
rules={{ required: true }} | ||
size="small" | ||
disabled={disabled} | ||
/> | ||
<FormTextField | ||
name={`${name}.${index}.url`} | ||
label="Lien" | ||
control={control} | ||
size="small" | ||
fullWidth | ||
disabled={disabled} | ||
/> | ||
{!disabled && ( | ||
<IconButton aria-label="delete" onClick={onDelete}> | ||
<DeleteIcon /> | ||
</IconButton> | ||
)} | ||
</Stack> | ||
); | ||
}; | ||
|
||
type Props = { | ||
name: string; | ||
control: Control<any>; | ||
disabled?: boolean; | ||
}; | ||
|
||
export const FormOtherReferences = ({ | ||
name, | ||
control, | ||
disabled = false, | ||
}: Props): React.ReactElement => { | ||
const { fields, append, remove } = useFieldArray({ | ||
control, | ||
name, | ||
}); | ||
|
||
const onAdd = () => { | ||
append({ | ||
label: "", | ||
url: "", | ||
}); | ||
}; | ||
|
||
return ( | ||
<TitleBox title="Autres références" disabled={disabled}> | ||
<Stack spacing={2} mt={4}> | ||
{fields.map((field, index) => { | ||
return ( | ||
<OtherReferenceLine | ||
key={field.id} | ||
name={name} | ||
control={control} | ||
index={index} | ||
onDelete={() => remove(index)} | ||
disabled={disabled} | ||
/> | ||
); | ||
})} | ||
{!disabled && ( | ||
<Button startIcon={<AddIcon />} size="small" onClick={onAdd}> | ||
Ajouter une référence | ||
</Button> | ||
)} | ||
</Stack> | ||
</TitleBox> | ||
); | ||
}; |
2 changes: 2 additions & 0 deletions
2
targets/frontend/src/components/forms/OtherReferences/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./FormOtherReferences"; | ||
export * from "./type"; |
4 changes: 4 additions & 0 deletions
4
targets/frontend/src/components/forms/OtherReferences/type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type OtherReference = { | ||
label: string; | ||
url: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.