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: require confirmation on attachment removal and when cancelling edit #2875

Merged
merged 3 commits into from
Mar 13, 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
3 changes: 2 additions & 1 deletion frontend/benefit/handler/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@
},
"attachmentsIngress": "Lisää hakemukselle seuraavat liitteet. Kaikki *-merkityt liitteet ovat pakollisia. Tiedostomuoto voi olla JPG, PNG tai PDF ja kooltaan maksimissaan 10 MB.",
"add": "Liitä tiedosto",
"remove": "Poista liite"
"remove": "Poista liite",
"confirm": "Haluatko varmasti poistaa liitteen {{ name }}? Se poistuu heti eikä tiedostoa voida enää palauttaa."
}
},
"summary": {
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/handler/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@
},
"attachmentsIngress": "Lisää hakemukselle seuraavat liitteet. Kaikki *-merkityt liitteet ovat pakollisia. Tiedostomuoto voi olla JPG, PNG tai PDF ja kooltaan maksimissaan 10 MB.",
"add": "Liitä tiedosto",
"remove": "Poista liite"
"remove": "Poista liite",
"confirm": "Haluatko varmasti poistaa liitteen {{ name }}? Se poistuu heti eikä tiedostoa voida enää palauttaa."
}
},
"summary": {
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/handler/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@
},
"attachmentsIngress": "Lisää hakemukselle seuraavat liitteet. Kaikki *-merkityt liitteet ovat pakollisia. Tiedostomuoto voi olla JPG, PNG tai PDF ja kooltaan maksimissaan 10 MB.",
"add": "Liitä tiedosto",
"remove": "Poista liite"
"remove": "Poista liite",
"confirm": "Haluatko varmasti poistaa liitteen {{ name }}? Se poistuu heti eikä tiedostoa voida enää palauttaa."
}
},
"summary": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ const ActionBarEdit: React.FC<ActionBarProps> = ({
theme="black"
variant="secondary"
onClick={() => {
// eslint-disable-next-line no-alert
const alert = formik.dirty && !window.confirm();
const alert =
formik.dirty &&
// eslint-disable-next-line no-alert
!window.confirm(
t(
'common:applications.actions.backWithoutSavingDescription'
)
);

if (!alert) {
return void router.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const AttachmentsList: React.FC<AttachmentsListProps> = ({
translationsBase,
isRemoving,
isUploading,
} = useAttachmentsList(handleQuietSave);
} = useAttachmentsList(handleQuietSave, attachments);

return (
<AttachmentsListBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type ExtendedComponentProps = {
};

const useAttachmentsList = (
handleQuietSave?: () => Promise<ApplicationData | void>
handleQuietSave?: () => Promise<ApplicationData | void>,
attachments?: BenefitAttachment[]
): ExtendedComponentProps => {
const router = useRouter();
const id = router?.query?.id;
Expand Down Expand Up @@ -59,7 +60,16 @@ const useAttachmentsList = (

const handleRemove = async (attachmentId: string): Promise<void> => {
const response = handleQuietSave ? await handleQuietSave() : true;
if (response) {
const attachment = attachments?.find((file) => file.id === attachmentId);
if (
response &&
// eslint-disable-next-line no-alert
window.confirm(
t('common:applications.sections.attachments.confirm', {
name: attachment?.attachmentFileName,
})
)
) {
removeAttachment({
applicationId,
attachmentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const useApplicationForm = (): ExtendedComponentProps => {
[APPLICATION_FIELDS.PAPER_APPLICATION_DATE]:
application.paperApplicationDate
? formatDate(parseDate(application.paperApplicationDate))
: undefined,
: formatDate(new Date()),
},
validationSchema: getValidationSchema(organizationType, t),
validateOnChange: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Props<T extends Attachment> = {
errorMessage?: string | false;
attachments?: T[];
onUpload: (data: FormData) => void | Promise<void>;
onRemove: (fileId: string) => void | Promise<void>;
onRemove: (fileId: string, fileName?: string) => void | Promise<void>;
onOpen: (attachment: T) => void | Promise<void>;
isUploading: boolean;
isRemoving: boolean;
Expand Down
Loading