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

Fix/estimation delete bug #321

Merged
merged 4 commits into from
Jan 6, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,67 @@ import { redirect } from "next/navigation";
import { EstimationOverviewCard } from "@/src/components/estimation/estimation-overview-card";
import Button from "@codegouvfr/react-dsfr/Button";
import { GenericFicheLink } from "@/src/components/common/generic-save-fiche/generic-fiche-link";
import { useEffect, useState } from "react";
import { useCanEditProjet } from "@/src/hooks/use-can-edit-projet";

export default function CreateEstimationPage() {
export default function ListeEstimationPage() {
const currentProjet = useProjetsStore((state) => state.getCurrentProjet());
const canEditProjet = useCanEditProjet(currentProjet?.id);
const [shouldRedirect, setShouldRedirect] = useState(false);

if (!currentProjet) {
return null;
}
if (currentProjet.estimations.length < 1) {
if (canEditProjet) {
useEffect(() => {
if (shouldRedirect && currentProjet) {
redirect(PFMV_ROUTES.ESPACE_PROJET_CREATION_ESTIMATION(currentProjet.id));
} else {
return (
<div className="fr-container pt-8">
<div className="mb-2 text-2xl font-bold">{"Aucune estimation n'a été faite pour ce projet"}</div>
</div>
);
}
} else {
}, [currentProjet, shouldRedirect]);

if (!currentProjet) return null;
if (!currentProjet.estimations.length) {
if (canEditProjet) {
!shouldRedirect && setShouldRedirect(true);
return null;
}
return (
<div className="fr-container pt-8">
<div className="mb-2 text-2xl font-bold">{"Je fais une estimation de budget pour mon projet"}</div>
<div className="text-lg">{`Mes solutions sélectionnées pour mon projet ${currentProjet?.nom}.`}</div>
<div className="mb-10 text-lg">
{`Vous pouvez estimer une fourchette de prix en fonction des matériaux et systèmes choisis.`}
</div>
<div className="flex flex-col gap-12">
{currentProjet.estimations.map((estimation) => (
<EstimationOverviewCard key={estimation.id} estimation={estimation} canEditEstimation={canEditProjet} />
))}
</div>
<div className="mt-12 flex flex-row gap-6">
{canEditProjet && (
<Button
className="rounded-3xl"
iconId="ri-add-circle-fill"
iconPosition="left"
linkProps={{ href: PFMV_ROUTES.ESPACE_PROJET_CREATION_ESTIMATION(currentProjet.id), target: "_self" }}
>
Ajouter une estimation
</Button>
)}
<GenericFicheLink
href={PFMV_ROUTES.ESPACE_PROJET_TABLEAU_DE_BORD}
className="fr-btn fr-btn--secondary rounded-3xl"
>
Revenir au tableau de bord
</GenericFicheLink>
</div>
<div className="mb-2 text-2xl font-bold">Aucune estimation {"n'a"} été faite pour ce projet</div>
</div>
);
}

return (
<div className="fr-container pt-8">
<div className="mb-10">
<div className="mb-2 text-2xl font-bold">Je fais une estimation de budget pour mon projet</div>
<div className="text-lg">Mes solutions sélectionnées pour mon projet {currentProjet.nom}.</div>
<div className="text-lg">
Vous pouvez estimer une fourchette de prix en fonction des matériaux et systèmes choisis.
</div>
</div>

<div className="flex flex-col gap-12">
{currentProjet.estimations.map((estimation) => (
<EstimationOverviewCard key={estimation.id} estimation={estimation} canEditEstimation={canEditProjet} />
))}
</div>

<div className="mt-12 flex flex-row gap-6">
{canEditProjet && (
<Button
className="rounded-3xl"
iconId="ri-add-circle-fill"
iconPosition="left"
linkProps={{ href: PFMV_ROUTES.ESPACE_PROJET_CREATION_ESTIMATION(currentProjet.id), target: "_self" }}
>
Ajouter une estimation
</Button>
)}
<GenericFicheLink
href={PFMV_ROUTES.ESPACE_PROJET_TABLEAU_DE_BORD}
className="fr-btn fr-btn--secondary rounded-3xl"
>
Revenir au tableau de bord
</GenericFicheLink>
</div>
</div>
);
}
Loading