Skip to content

Commit

Permalink
🐛 Fix: url for success box ssr (#2657)
Browse files Browse the repository at this point in the history
  • Loading branch information
VioMrqs authored Jan 24, 2025
1 parent e0693eb commit b9e7e21
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ComponentProps, FC } from 'react';
import React, { ComponentProps, FC, useEffect } from 'react';
import { Alerte } from './Alerte';

type AlertBoxProps = ComponentProps<'div'> & { title?: string };
Expand All @@ -8,4 +8,13 @@ export const SuccessBox: FC<AlertBoxProps> = ({
children,
className = '',
...props
}: AlertBoxProps) => <Alerte {...{ ...props, type: 'Succès', title, className, children }} />;
}: AlertBoxProps) => {
useEffect(() => {
window.scrollTo({
top: 0,
left: 0,
});
}, []);

return <Alerte {...{ ...props, type: 'Succès', title, className, children }} />;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Alert from '@codegouvfr/react-dsfr/Alert';
import { useRouter, useSearchParams } from 'next/navigation';
import { FC, useEffect } from 'react';

type Props = {
Expand All @@ -13,9 +14,27 @@ export const FormSuccessAlert: FC<Props> = ({ message }) => {
});
}, []);

const searchParams = useSearchParams();
const router = useRouter();

const handleRemoveQueryParam = () => {
const params = new URLSearchParams(searchParams.toString());
params.delete('success');

const newUrl = `${window.location.pathname}?${params.toString()}`;
router.replace(newUrl, { scroll: false });
};

return (
<div className="mb-4">
<Alert small closable severity="success" description={<p>{message}</p>} />
<Alert
small
closable
severity="success"
onClose={handleRemoveQueryParam}
description={<p>{message}</p>}
className="min-h-10"
/>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const action: FormAction<FormState, typeof schema> = async (
status: 'success',
redirection: {
url: Routes.Gestionnaire.lister,
message: `Gestionnaire réseau ${raisonSociale} ajouté`,
message: `Le gestionnaire réseau ${raisonSociale} a été ajouté`,
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const action: FormAction<FormState, typeof schema> = (_, { fichierCorrections })
status: 'success',
redirection: {
url: Routes.Raccordement.lister,
message: `${success} références de dossier de raccordement mises à jour`,
message: `${success} références de dossier de raccordement ont été mises à jour`,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const action: FormAction<FormState, typeof schema> = (
url: role.aLaPermission('raccordement.consulter')
? Routes.Raccordement.détail(identifiantProjet)
: Routes.Raccordement.lister,
message: 'Référence du dossier de raccordement modifiée',
message: 'La référence du dossier de raccordement a été modifiée',
},
};
});
Expand Down

0 comments on commit b9e7e21

Please sign in to comment.