Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display communes from epci #101

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions components/api-depot/client/client-form/perimeter-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ const PerimeterList = ({ perimeters, handlePerimeter }: PerimeterListProps) => {
key={idx}
className="fr-container fr-my-2w fr-grid-row fr-grid-row--gutters fr-grid-row--bottom"
>
<Perimeter
type={p.type}
code={p.code}
handlePerimeter={(p) => handleChange(p, idx)}
/>

<div className="fr-col-1">
<div className="fr-col-8">
<Perimeter
type={p.type}
code={p.code}
handlePerimeter={(p) => handleChange(p, idx)}
/>
</div>
<div className="fr-col-2">
<Button
iconId="fr-icon-delete-bin-line"
onClick={(e) => removePerimeter(e, idx)}
Expand Down
22 changes: 19 additions & 3 deletions components/api-depot/client/client-form/perimeter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import allCommunes from "@etalab/decoupage-administratif/data/communes.json";
import AutocompleteInput from "@/components/autocomplete-input";
import SelectInput from "@/components/select-input";
import { PerimeterType, TypePerimeterEnum } from "types/api-depot";
import { useFuse } from "@/hooks/use-fuse";
import { Tooltip } from "@codegouvfr/react-dsfr/Tooltip";
import Badge from "@codegouvfr/react-dsfr/Badge";

const typeOptions = [
{ label: "EPCI", value: "epci" },
Expand Down Expand Up @@ -74,9 +75,19 @@ const Perimeter = ({ type, code, handlePerimeter }: PerimetreProps) => {
}
};

const communeFromEPCI = useMemo(() => {
if (type === TypePerimeterEnum.EPCI) {
return epcis
.find((epci) => epci.code === code)
?.membres.map((commune) => `${commune.nom} (${commune.code})`)
.join(", ");
}
return null;
}, [type, code]);

return (
<div className="fr-grid-row fr-grid-row--gutters">
<div className="fr-col-6">
<div className="fr-col-5">
<SelectInput
label="Type"
value={type}
Expand All @@ -88,7 +99,7 @@ const Perimeter = ({ type, code, handlePerimeter }: PerimetreProps) => {
/>
</div>

<div className="fr-col-6">
<div className="fr-col-5">
<AutocompleteInput
id={uniqueId()}
label="Code"
Expand All @@ -97,6 +108,11 @@ const Perimeter = ({ type, code, handlePerimeter }: PerimetreProps) => {
onChange={handleChange}
/>
</div>
<div className="fr-col-2" style={{ alignContent: "end" }}>
{type === TypePerimeterEnum.EPCI && (
<Tooltip kind="hover" title={communeFromEPCI} />
)}
</div>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"typeorm:migration:down": "yarn typeorm migration:revert -- -d ./typeorm.config.ts"
},
"dependencies": {
"@codegouvfr/react-dsfr": "^0.69.0",
"@codegouvfr/react-dsfr": "^1.14.7",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@etalab/decoupage-administratif": "^4.0.0",
Expand Down
19 changes: 10 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@
"@babel/helper-validator-identifier" "^7.22.20"
to-fast-properties "^2.0.0"

"@codegouvfr/react-dsfr@^0.69.0":
version "0.69.0"
resolved "https://registry.yarnpkg.com/@codegouvfr/react-dsfr/-/react-dsfr-0.69.0.tgz#51d818fadc1fc73f5bb23fd98f63d6507a0296aa"
integrity sha512-5hLoGUSBDmXxiHGu3Q3Z7cX2iVL60KEyu6zvGSUZ77DW04yEGYtR31iHdi4RQl6tFYYtSZnoNNLxuRRQJSEdqQ==
"@codegouvfr/react-dsfr@^1.14.7":
version "1.14.7"
resolved "https://registry.yarnpkg.com/@codegouvfr/react-dsfr/-/react-dsfr-1.14.7.tgz#1d7c95adf6afa252e43a9064feb6ac413974f49c"
integrity sha512-NCq1aMl4tA5rgY8Iu+q74s7CjS8wytW0TACqvVlBRFxuoijkDNnHyiEdfPZgHcz8ZAR0BJqQfrHeVTVFVXTYHQ==
dependencies:
tsafe "^1.6.3"
tsafe "^1.7.2"
yargs-parser "^21.1.1"

"@colors/[email protected]", "@colors/colors@^1.6.0":
version "1.6.0"
Expand Down Expand Up @@ -4649,10 +4650,10 @@ ts-node@^10.9.2:
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

tsafe@^1.6.3:
version "1.6.4"
resolved "https://registry.yarnpkg.com/tsafe/-/tsafe-1.6.4.tgz#048a114761714538c72f16abd25bb247d4e3780e"
integrity sha512-l4Z54QFGHO8GF0gBpb3yPGHjkIkIirl8rwW+lMBmtEMzOJeRs8BdjkDEx6nU8Ak9PQVp/KNDtECxTja8MMIDoA==
tsafe@^1.7.2:
version "1.8.5"
resolved "https://registry.yarnpkg.com/tsafe/-/tsafe-1.8.5.tgz#cdf9fa3111974ac480d7ee519f8241815e5d22ea"
integrity sha512-LFWTWQrW6rwSY+IBNFl2ridGfUzVsPwrZ26T4KUJww/py8rzaQ/SY+MIz6YROozpUCaRcuISqagmlwub9YT9kw==

tsconfig-paths@^3.14.2:
version "3.14.2"
Expand Down
Loading