Skip to content

Commit 8519415

Browse files
Merge branch 'feature/contracts' into develop
2 parents e92fd31 + 5df539c commit 8519415

14 files changed

Lines changed: 147 additions & 49 deletions

File tree

frontend/src/assets/locales/en/translation.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,8 @@
11131113
"see_contract_details": "See contract details"
11141114
},
11151115
"error": {
1116-
"empty_signature": "The signature is required"
1116+
"empty_signature": "The signature is required",
1117+
"error_signing": "An error occurred while signing the contract!"
11171118
}
11181119
},
11191120
"reject": {
@@ -1312,4 +1313,4 @@
13121313
"clear": "Clear",
13131314
"apply_all": "Apply to all"
13141315
}
1315-
}
1316+
}

frontend/src/assets/locales/ro/translation.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,8 @@
11191119
"see_contract_details": "Vezi detaliile contractului"
11201120
},
11211121
"error": {
1122-
"empty_signature": "Semnătura este obligatorie"
1122+
"empty_signature": "Semnătura este obligatorie",
1123+
"error_signing": "A apărut o eroare la semnarea contractului!"
11231124
}
11241125
},
11251126
"reject": {
@@ -1153,8 +1154,10 @@
11531154
"edit_title": "Editează template",
11541155
"success_add": "Template-ul a fost adaugat!",
11551156
"success_edit": "Template-ul a fost actualizat!",
1157+
"success_delete": "Template-ul a fost eliminat!",
11561158
"error_add": "Eroare la adaugarea template-ului!",
11571159
"error_edit": "Eroare la actualizarea template-ului!",
1160+
"error_delete": "Eroare la eliminarea template-ului!",
11581161
"subheading": {
11591162
"p1": "Acest template a fost realizat respectând normele din domeniu.",
11601163
"p1_link": "Află mai multe",
@@ -1179,6 +1182,11 @@
11791182
"download_all": "Descarcă toate"
11801183
}
11811184
},
1185+
"delete_modal": {
1186+
"title": "Confirmă eliminarea template-ului",
1187+
"description": "Ești sigur că vrei să elimini template-ul?",
1188+
"confirm_btn_label": "Da, elimină"
1189+
},
11821190
"tooltip": "Datele contractului (Numărul, perioada contractului și data întemeierii) se completează în momentul atribuirii contractului către unul sau mai mulți voluntari.",
11831191
"template_name": "Numele template-ului",
11841192
"organization": {

frontend/src/components/DocumentTemplatesTable.tsx

Lines changed: 75 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import CardBody from './CardBody';
44
import DataTableComponent from './DataTableComponent';
55
import Card from '../layouts/CardLayout';
66
import CardHeader from './CardHeader';
77
import { IDocumentTemplateListItem } from '../common/interfaces/template.interface';
8-
import { useDocumentTemplatesQuery } from '../services/documents-templates/documents-templates.service';
8+
import { useDeleteDocumentTemplateMutation, useDocumentTemplatesQuery } from '../services/documents-templates/documents-templates.service';
99
import { OrderDirection } from '../common/enums/order-direction.enum';
1010
import { format } from 'date-fns';
1111
import { SortOrder, TableColumn } from 'react-data-table-component';
@@ -14,6 +14,8 @@ import { ArrowDownTrayIcon, EyeIcon, PencilIcon, PlusIcon, TrashIcon } from '@he
1414
import Popover from './Popover';
1515
import { Link, useNavigate } from 'react-router-dom';
1616
import Button from './Button';
17+
import ConfirmationModal from './ConfirmationModal';
18+
import { useErrorToast, useSuccessToast } from '../hooks/useToast';
1719

1820
const createArchiveRoute = (name: string) => `/actions-archive?author=${name.split(' ').join('+')}`;
1921

@@ -64,14 +66,40 @@ const DocumentTemplatesTableHeader = [
6466
export const DocumentTemplatesTable = ({ query, setQuery }: DocumentTemplatesProps) => {
6567
const { t } = useTranslation(['doc_templates']);
6668
const navigate = useNavigate();
69+
const [selectedDeleteDocumentTemplate, setSelectedDeleteDocumentTemplate] = useState<IDocumentTemplateListItem | null>(null);
6770

68-
const { data: templates, isLoading: isLoadingDocumentTemplates } = useDocumentTemplatesQuery({
71+
const { data: templates, isLoading: isLoadingDocumentTemplates, refetch } = useDocumentTemplatesQuery({
6972
limit: 10,
7073
page: 1,
7174
orderBy: 'name',
7275
orderDirection: OrderDirection.ASC,
7376
});
7477

78+
const { mutate: deleteDocumentTemplate } = useDeleteDocumentTemplateMutation();
79+
80+
const handleDeleteDocumentTemplate = (template: IDocumentTemplateListItem) => {
81+
setSelectedDeleteDocumentTemplate(template);
82+
};
83+
84+
const handleCancelDelete = () => {
85+
setSelectedDeleteDocumentTemplate(null);
86+
};
87+
88+
const handleConfirmDelete = () => {
89+
if (selectedDeleteDocumentTemplate) {
90+
deleteDocumentTemplate(selectedDeleteDocumentTemplate?.id, {
91+
onSuccess: () => {
92+
setSelectedDeleteDocumentTemplate(null);
93+
useSuccessToast(t('success_delete'));
94+
refetch();
95+
},
96+
onError: () => {
97+
useErrorToast(t('error_delete'));
98+
},
99+
});
100+
}
101+
};
102+
75103
// pagination
76104
const onRowsPerPageChange = (limit: number) => {
77105
setQuery(
@@ -125,7 +153,7 @@ export const DocumentTemplatesTable = ({ query, setQuery }: DocumentTemplatesPro
125153
{
126154
label: t('table.table_actions.delete'),
127155
icon: <TrashIcon className="menu-icon" />,
128-
onClick: () => { },
156+
onClick: (row: IDocumentTemplateListItem) => { handleDeleteDocumentTemplate(row) },
129157
alert: true,
130158
},
131159
];
@@ -152,38 +180,50 @@ export const DocumentTemplatesTable = ({ query, setQuery }: DocumentTemplatesPro
152180
};
153181

154182
return (
155-
<Card>
156-
<CardHeader>
157-
<h2>{t('table.title')}</h2>
158-
<div className="flex gap-2 lg:gap-6">
159-
<Button
160-
label={t('table.table_header.download_all')}
161-
className="btn-outline-secondary"
162-
icon={<ArrowDownTrayIcon className="h-5 w-5" />}
163-
onClick={() => { }}
164-
/>
165-
<Button
166-
label={t('table.table_header.create')}
167-
className="btn-primary"
168-
icon={<PlusIcon className="h-5 w-5" />}
169-
onClick={() => navigate('/documents/templates/create')}
183+
<>
184+
<Card>
185+
<CardHeader>
186+
<h2>{t('table.title')}</h2>
187+
<div className="flex gap-2 lg:gap-6">
188+
<Button
189+
label={t('table.table_header.download_all')}
190+
className="btn-outline-secondary"
191+
icon={<ArrowDownTrayIcon className="h-5 w-5" />}
192+
onClick={() => { }}
193+
/>
194+
<Button
195+
label={t('table.table_header.create')}
196+
className="btn-primary"
197+
icon={<PlusIcon className="h-5 w-5" />}
198+
onClick={() => navigate('/documents/templates/create')}
199+
/>
200+
</div>
201+
</CardHeader>
202+
<CardBody>
203+
<DataTableComponent
204+
columns={[...DocumentTemplatesTableHeader, buildDocumentTemplatesTableActions()]}
205+
data={templates?.items}
206+
loading={isLoadingDocumentTemplates}
207+
pagination
208+
paginationPerPage={10}
209+
paginationTotalRows={templates?.items?.length}
210+
paginationDefaultPage={query.page as number}
211+
onChangeRowsPerPage={onRowsPerPageChange}
212+
onChangePage={onChangePage}
213+
onSort={onSort}
170214
/>
171-
</div>
172-
</CardHeader>
173-
<CardBody>
174-
<DataTableComponent
175-
columns={[...DocumentTemplatesTableHeader, buildDocumentTemplatesTableActions()]}
176-
data={templates?.items}
177-
loading={isLoadingDocumentTemplates}
178-
pagination
179-
paginationPerPage={10}
180-
paginationTotalRows={templates?.items?.length}
181-
paginationDefaultPage={query.page as number}
182-
onChangeRowsPerPage={onRowsPerPageChange}
183-
onChangePage={onChangePage}
184-
onSort={onSort}
215+
</CardBody>
216+
</Card>
217+
{selectedDeleteDocumentTemplate &&
218+
<ConfirmationModal
219+
onClose={handleCancelDelete}
220+
onConfirm={handleConfirmDelete}
221+
title={t('delete_modal.title')}
222+
description={t('delete_modal.description')}
223+
confirmBtnLabel={t('delete_modal.confirm_btn_label')}
224+
confirmBtnClassName="btn-danger"
185225
/>
186-
</CardBody>
187-
</Card>
226+
}
227+
</>
188228
);
189229
};

frontend/src/components/SignatureContent.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useTranslation } from 'react-i18next';
99
import { ArrowLeftIcon, CheckIcon, XMarkIcon } from '@heroicons/react/24/outline';
1010
import LoadingContent from './LoadingContent';
1111
import Button from './Button';
12-
12+
import { useErrorToast } from '../hooks/useToast';
1313
export const SignatureContent = ({
1414
contract,
1515
setSidePanelContent,
@@ -71,6 +71,11 @@ export const SignatureContent = ({
7171
onSuccess: () => {
7272
setSidePanelContent(2);
7373
},
74+
onError: () => {
75+
useErrorToast(t('sign.error.error_signing'));
76+
// show contract info content
77+
setSidePanelContent(0);
78+
},
7479
onSettled: () => {
7580
queryClient.invalidateQueries({
7681
queryKey: ['document-contract', contract?.documentId],

frontend/src/services/documents-templates/documents-templates.api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ export const updateContractTemplate = (id: string, data: IAddContractTemplatePay
3232
export const getContractTemplate = (id: string) => {
3333
return API.get(`/documents/templates/${id}`).then((res) => res.data);
3434
};
35+
36+
export const deleteContractTemplate = (id: string) => {
37+
return API.delete(`/documents/templates/${id}`).then((res) => res.data);
38+
};

frontend/src/services/documents-templates/documents-templates.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useMutation, useQuery } from 'react-query';
22
import {
33
addContractTemplate,
4+
deleteContractTemplate,
45
getContractTemplate,
56
getTemplateById,
67
getTemplates,
@@ -89,3 +90,12 @@ export const useDocumentTemplateByIdQuery = (id?: string) => {
8990
enabled: !!id,
9091
});
9192
};
93+
94+
export const useDeleteDocumentTemplateMutation = () => {
95+
return useMutation((id: string) => deleteContractTemplate(id), {
96+
onError: (error) => {
97+
console.log('⭕️ ERROR IN DELETE DOCUMENT TEMPLATE MUTATION ⭕️', error);
98+
return Promise.resolve(error);
99+
},
100+
});
101+
};

mobile/app.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const expoConfig: ExpoConfig = {
7070
url: 'https://u.expo.dev/6aaad982-5a5c-4af8-b66c-7689afe74e1f',
7171
},
7272
runtimeVersion: {
73-
policy: 'sdkVersion',
73+
policy: 'appVersion',
7474
},
7575
owner: 'commit-global',
7676
};

mobile/src/assets/locales/en/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@
129129
"label": "City"
130130
},
131131
"birthday": {
132-
"label": "Date of birth"
132+
"label": "Date of birth",
133+
"required": "The date of birth is required"
133134
}
134135
}
135136
}

mobile/src/assets/locales/ro/translation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@
129129
"label": "Oraș"
130130
},
131131
"birthday": {
132-
"label": "Data nașterii"
132+
"label": "Data nașterii",
133+
"required": "Data nașterii este obligatorie"
133134
}
134135
}
135136
}

mobile/src/common/utils/document-contracts.helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
} from '../interfaces/user-profile.interface';
99

1010
export const isOver16 = (birthday: string | Date) => {
11+
if (!birthday) {
12+
return true;
13+
}
1114
const birthdayDate = typeof birthday === 'string' ? parseISO(birthday) : birthday;
1215
const today = new Date();
1316
const age = differenceInYears(today, birthdayDate);

0 commit comments

Comments
 (0)