Skip to content

Commit

Permalink
fix: require confirm on attachment removal and on edit cancel (HL-1199
Browse files Browse the repository at this point in the history
…#2875)

* feat: require user confirmation on attachment deletion event

* fix: add forgotten translation on cancel confirmation

* fix: set paper application date to today if it's undefined
  • Loading branch information
sirtawast authored Mar 13, 2024
1 parent 9d6e95a commit b8de140
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 10 deletions.
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

0 comments on commit b8de140

Please sign in to comment.