Skip to content

Commit

Permalink
fix list PDR filters, update link from pdr
Browse files Browse the repository at this point in the history
  • Loading branch information
achorein committed Oct 30, 2024
1 parent 4088a3e commit b74d833
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions admin/src/components/filters-system-v2/components/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export default function Filters({
}
const newCategories: string[] = [];
filtersVisible?.forEach((f) => {
if (!newCategories.includes(f.parentGroup || "")) {
newCategories.push(f.parentGroup || "");
if (!newCategories.includes(f.parentGroup!)) {
newCategories.push(f.parentGroup!);
}
});
setCategories(newCategories);
Expand Down
9 changes: 4 additions & 5 deletions admin/src/scenes/plan-transport/ligne-bus/ListPDR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ export default function ListPDR(props: RouteComponentProps<{ id: string }>) {
const [PDR, setPDR] = React.useState<PointDeRassemblementType>();

const cohort = new URLSearchParams(props.location.search).get("cohort");
const ligneId = new URLSearchParams(props.location.search).get("ligneId");

const id = props.match && props.match.params && props.match.params.id;
if (!id) return <div />;
const id = props.match?.params?.id;

const fetchData = async () => {
try {
if (!id || !cohort) return <div />;
if (!id || !cohort) return;

const { ok, code, data } = await api.get(`/point-de-rassemblement/${id}/bus/${cohort}`);
if (!ok) {
Expand Down Expand Up @@ -159,6 +157,7 @@ export default function ListPDR(props: RouteComponentProps<{ id: string }>) {
});
}

if (!id) return <div />;
if (loading) return <Loader />;

const filterArray: Filter[] = [
Expand Down Expand Up @@ -231,7 +230,7 @@ export default function ListPDR(props: RouteComponentProps<{ id: string }>) {
<div className="flex items-stretch justify-between bg-white px-4 pt-2">
<div className="flex items-center gap-2">
<Filters
defaultUrlParam={ligneId ? `cohort=${cohort}&ligneId=${ligneId}` : `cohort=${cohort}`}
defaultUrlParam={`cohort=${cohort}`}
pageId={pageId}
route={`/elasticsearch/young/by-point-de-rassemblement/${PDR?._id}/search`}
setData={(value) => setData(value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export default function PointDeRassemblement({ bus, setBus, index, pdr, volume,
const refInput = React.useRef<HTMLInputElement>(null);
const refContainer = React.useRef<HTMLDivElement>(null);

const youngsCount = volume?.find((v) => v.meetingPointId === pdr._id)?.youngsCount || 0;

React.useEffect(() => {
const handleClickOutside = (event) => {
if (refContainer.current && refContainer.current.contains(event.target)) {
Expand Down Expand Up @@ -137,7 +139,7 @@ export default function PointDeRassemblement({ bus, setBus, index, pdr, volume,
setFilteredPDR(filteredPDR);
}, [search, listPDR, bus]);

const onSubmitInfo = async () => {
const handleSubmitInfo = async () => {
try {
setIsLoading(true);
setErrors({});
Expand Down Expand Up @@ -183,12 +185,13 @@ export default function PointDeRassemblement({ bus, setBus, index, pdr, volume,
}
};

if (!volume)
if (!volume) {
return (
<div className="w-full rounded-xl bg-white p-8">
<Loader />
</div>
);
}

return (
<div className="w-full rounded-xl bg-white p-8">
Expand All @@ -211,7 +214,7 @@ export default function PointDeRassemblement({ bus, setBus, index, pdr, volume,
<div className="absolute top-0 right-0 flex flex-col items-end justify-end gap-2">
<button
className="flex cursor-pointer items-center gap-2 rounded-full border-[1px] border-blue-100 bg-blue-100 px-3 py-2 text-xs leading-5 text-blue-600 hover:border-blue-600 disabled:cursor-not-allowed disabled:opacity-50"
onClick={onSubmitInfo}
onClick={handleSubmitInfo}
disabled={isLoading}>
<Pencil stroke="#2563EB" className="mr-[6px] h-[12px] w-[12px]" />
Enregistrer les changements
Expand Down Expand Up @@ -249,7 +252,7 @@ export default function PointDeRassemblement({ bus, setBus, index, pdr, volume,
</p>
</div>
<div className="mt-8 flex flex-col gap-4">
{user.role === ROLES.ADMIN && editPdr && !volume.find((v) => v.meetingPointId === pdr._id)?.youngsCount && (
{user.role === ROLES.ADMIN && editPdr && !youngsCount && (
<div className="relative">
<div
ref={refContainer}
Expand Down Expand Up @@ -362,8 +365,11 @@ export default function PointDeRassemblement({ bus, setBus, index, pdr, volume,
</div>
<div className="mt-3 flex items-center gap-2">
<div className="pb-1 text-lg font-medium leading-5 text-gray-900"> </div>
<Link to={`/ligne-de-bus/volontaires/point-de-rassemblement/${pdr._id?.toString()}?cohort=${cohort?.name}`} className="w-full">
<Button type="tertiary" title={`Voir les volontaires (${volume.find((v) => v.meetingPointId === pdr._id)?.youngsCount || 0})`} className="w-full max-w-none" />
<Link
target="_blank"
to={`/ligne-de-bus/volontaires/point-de-rassemblement/${pdr._id?.toString()}?cohort=${cohort?.name}&ligneId=${bus._id.toString()}`}
className="w-full">
<Button type="tertiary" title={`Voir les volontaires attendus (${youngsCount})`} className="w-full max-w-none" />
</Link>
</div>
<div className="mt-8 flex justify-end">
Expand Down

0 comments on commit b74d833

Please sign in to comment.