Skip to content

Commit

Permalink
Merge branch 'feature/contracts' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
radulescuandrew committed Oct 1, 2024
2 parents e92fd31 + 5df539c commit 8519415
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 49 deletions.
5 changes: 3 additions & 2 deletions frontend/src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,8 @@
"see_contract_details": "See contract details"
},
"error": {
"empty_signature": "The signature is required"
"empty_signature": "The signature is required",
"error_signing": "An error occurred while signing the contract!"
}
},
"reject": {
Expand Down Expand Up @@ -1312,4 +1313,4 @@
"clear": "Clear",
"apply_all": "Apply to all"
}
}
}
10 changes: 9 additions & 1 deletion frontend/src/assets/locales/ro/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,8 @@
"see_contract_details": "Vezi detaliile contractului"
},
"error": {
"empty_signature": "Semnătura este obligatorie"
"empty_signature": "Semnătura este obligatorie",
"error_signing": "A apărut o eroare la semnarea contractului!"
}
},
"reject": {
Expand Down Expand Up @@ -1153,8 +1154,10 @@
"edit_title": "Editează template",
"success_add": "Template-ul a fost adaugat!",
"success_edit": "Template-ul a fost actualizat!",
"success_delete": "Template-ul a fost eliminat!",
"error_add": "Eroare la adaugarea template-ului!",
"error_edit": "Eroare la actualizarea template-ului!",
"error_delete": "Eroare la eliminarea template-ului!",
"subheading": {
"p1": "Acest template a fost realizat respectând normele din domeniu.",
"p1_link": "Află mai multe",
Expand All @@ -1179,6 +1182,11 @@
"download_all": "Descarcă toate"
}
},
"delete_modal": {
"title": "Confirmă eliminarea template-ului",
"description": "Ești sigur că vrei să elimini template-ul?",
"confirm_btn_label": "Da, elimină"
},
"tooltip": "Datele contractului (Numărul, perioada contractului și data întemeierii) se completează în momentul atribuirii contractului către unul sau mai mulți voluntari.",
"template_name": "Numele template-ului",
"organization": {
Expand Down
110 changes: 75 additions & 35 deletions frontend/src/components/DocumentTemplatesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import CardBody from './CardBody';
import DataTableComponent from './DataTableComponent';
import Card from '../layouts/CardLayout';
import CardHeader from './CardHeader';
import { IDocumentTemplateListItem } from '../common/interfaces/template.interface';
import { useDocumentTemplatesQuery } from '../services/documents-templates/documents-templates.service';
import { useDeleteDocumentTemplateMutation, useDocumentTemplatesQuery } from '../services/documents-templates/documents-templates.service';
import { OrderDirection } from '../common/enums/order-direction.enum';
import { format } from 'date-fns';
import { SortOrder, TableColumn } from 'react-data-table-component';
Expand All @@ -14,6 +14,8 @@ import { ArrowDownTrayIcon, EyeIcon, PencilIcon, PlusIcon, TrashIcon } from '@he
import Popover from './Popover';
import { Link, useNavigate } from 'react-router-dom';
import Button from './Button';
import ConfirmationModal from './ConfirmationModal';
import { useErrorToast, useSuccessToast } from '../hooks/useToast';

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

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

const { data: templates, isLoading: isLoadingDocumentTemplates } = useDocumentTemplatesQuery({
const { data: templates, isLoading: isLoadingDocumentTemplates, refetch } = useDocumentTemplatesQuery({
limit: 10,
page: 1,
orderBy: 'name',
orderDirection: OrderDirection.ASC,
});

const { mutate: deleteDocumentTemplate } = useDeleteDocumentTemplateMutation();

const handleDeleteDocumentTemplate = (template: IDocumentTemplateListItem) => {
setSelectedDeleteDocumentTemplate(template);
};

const handleCancelDelete = () => {
setSelectedDeleteDocumentTemplate(null);
};

const handleConfirmDelete = () => {
if (selectedDeleteDocumentTemplate) {
deleteDocumentTemplate(selectedDeleteDocumentTemplate?.id, {
onSuccess: () => {
setSelectedDeleteDocumentTemplate(null);
useSuccessToast(t('success_delete'));
refetch();
},
onError: () => {
useErrorToast(t('error_delete'));
},
});
}
};

// pagination
const onRowsPerPageChange = (limit: number) => {
setQuery(
Expand Down Expand Up @@ -125,7 +153,7 @@ export const DocumentTemplatesTable = ({ query, setQuery }: DocumentTemplatesPro
{
label: t('table.table_actions.delete'),
icon: <TrashIcon className="menu-icon" />,
onClick: () => { },
onClick: (row: IDocumentTemplateListItem) => { handleDeleteDocumentTemplate(row) },
alert: true,
},
];
Expand All @@ -152,38 +180,50 @@ export const DocumentTemplatesTable = ({ query, setQuery }: DocumentTemplatesPro
};

return (
<Card>
<CardHeader>
<h2>{t('table.title')}</h2>
<div className="flex gap-2 lg:gap-6">
<Button
label={t('table.table_header.download_all')}
className="btn-outline-secondary"
icon={<ArrowDownTrayIcon className="h-5 w-5" />}
onClick={() => { }}
/>
<Button
label={t('table.table_header.create')}
className="btn-primary"
icon={<PlusIcon className="h-5 w-5" />}
onClick={() => navigate('/documents/templates/create')}
<>
<Card>
<CardHeader>
<h2>{t('table.title')}</h2>
<div className="flex gap-2 lg:gap-6">
<Button
label={t('table.table_header.download_all')}
className="btn-outline-secondary"
icon={<ArrowDownTrayIcon className="h-5 w-5" />}
onClick={() => { }}
/>
<Button
label={t('table.table_header.create')}
className="btn-primary"
icon={<PlusIcon className="h-5 w-5" />}
onClick={() => navigate('/documents/templates/create')}
/>
</div>
</CardHeader>
<CardBody>
<DataTableComponent
columns={[...DocumentTemplatesTableHeader, buildDocumentTemplatesTableActions()]}
data={templates?.items}
loading={isLoadingDocumentTemplates}
pagination
paginationPerPage={10}
paginationTotalRows={templates?.items?.length}
paginationDefaultPage={query.page as number}
onChangeRowsPerPage={onRowsPerPageChange}
onChangePage={onChangePage}
onSort={onSort}
/>
</div>
</CardHeader>
<CardBody>
<DataTableComponent
columns={[...DocumentTemplatesTableHeader, buildDocumentTemplatesTableActions()]}
data={templates?.items}
loading={isLoadingDocumentTemplates}
pagination
paginationPerPage={10}
paginationTotalRows={templates?.items?.length}
paginationDefaultPage={query.page as number}
onChangeRowsPerPage={onRowsPerPageChange}
onChangePage={onChangePage}
onSort={onSort}
</CardBody>
</Card>
{selectedDeleteDocumentTemplate &&
<ConfirmationModal
onClose={handleCancelDelete}
onConfirm={handleConfirmDelete}
title={t('delete_modal.title')}
description={t('delete_modal.description')}
confirmBtnLabel={t('delete_modal.confirm_btn_label')}
confirmBtnClassName="btn-danger"
/>
</CardBody>
</Card>
}
</>
);
};
7 changes: 6 additions & 1 deletion frontend/src/components/SignatureContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useTranslation } from 'react-i18next';
import { ArrowLeftIcon, CheckIcon, XMarkIcon } from '@heroicons/react/24/outline';
import LoadingContent from './LoadingContent';
import Button from './Button';

import { useErrorToast } from '../hooks/useToast';
export const SignatureContent = ({
contract,
setSidePanelContent,
Expand Down Expand Up @@ -71,6 +71,11 @@ export const SignatureContent = ({
onSuccess: () => {
setSidePanelContent(2);
},
onError: () => {
useErrorToast(t('sign.error.error_signing'));
// show contract info content
setSidePanelContent(0);
},
onSettled: () => {
queryClient.invalidateQueries({
queryKey: ['document-contract', contract?.documentId],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ export const updateContractTemplate = (id: string, data: IAddContractTemplatePay
export const getContractTemplate = (id: string) => {
return API.get(`/documents/templates/${id}`).then((res) => res.data);
};

export const deleteContractTemplate = (id: string) => {
return API.delete(`/documents/templates/${id}`).then((res) => res.data);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMutation, useQuery } from 'react-query';
import {
addContractTemplate,
deleteContractTemplate,
getContractTemplate,
getTemplateById,
getTemplates,
Expand Down Expand Up @@ -89,3 +90,12 @@ export const useDocumentTemplateByIdQuery = (id?: string) => {
enabled: !!id,
});
};

export const useDeleteDocumentTemplateMutation = () => {
return useMutation((id: string) => deleteContractTemplate(id), {
onError: (error) => {
console.log('⭕️ ERROR IN DELETE DOCUMENT TEMPLATE MUTATION ⭕️', error);
return Promise.resolve(error);
},
});
};
2 changes: 1 addition & 1 deletion mobile/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const expoConfig: ExpoConfig = {
url: 'https://u.expo.dev/6aaad982-5a5c-4af8-b66c-7689afe74e1f',
},
runtimeVersion: {
policy: 'sdkVersion',
policy: 'appVersion',
},
owner: 'commit-global',
};
Expand Down
3 changes: 2 additions & 1 deletion mobile/src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@
"label": "City"
},
"birthday": {
"label": "Date of birth"
"label": "Date of birth",
"required": "The date of birth is required"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion mobile/src/assets/locales/ro/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@
"label": "Oraș"
},
"birthday": {
"label": "Data nașterii"
"label": "Data nașterii",
"required": "Data nașterii este obligatorie"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions mobile/src/common/utils/document-contracts.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
} from '../interfaces/user-profile.interface';

export const isOver16 = (birthday: string | Date) => {
if (!birthday) {
return true;
}
const birthdayDate = typeof birthday === 'string' ? parseISO(birthday) : birthday;
const today = new Date();
const age = differenceInYears(today, birthdayDate);
Expand Down
17 changes: 14 additions & 3 deletions mobile/src/components/SignatureBottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { useEffect, useMemo, useState } from 'react';
import BottomSheet, { BottomSheetView } from '@gorhom/bottom-sheet';
import BottomSheet, {
BottomSheetBackdrop,
BottomSheetHandle,
BottomSheetView,
} from '@gorhom/bottom-sheet';
import { Animated, StyleSheet, View } from 'react-native';
import { useReducedMotion } from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
Expand All @@ -10,10 +14,10 @@ import { SvgXml } from 'react-native-svg';
import { Text, useTheme } from '@ui-kitten/components';
import InlineLink from './InlineLink';
import upsIcon from '../assets/svg/ups-icon';
import { renderBackdrop } from '../components/BottomSheet';
import { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
import { SignatureViewRef } from 'react-native-signature-canvas';
import LottieView from 'lottie-react-native';
import { renderBackdrop } from './BottomSheet';
interface SignatureBottomSheetProps {
bottomSheetRef: React.RefObject<BottomSheetMethods>;
snapPoints: number[];
Expand Down Expand Up @@ -134,14 +138,21 @@ export const SignatureBottomSheet = ({
const insets = useSafeAreaInsets();
const theme = useTheme();

const renderUncloseableBackdrop = (props: any) => {
return <BottomSheetBackdrop opacity={0.3} pressBehavior="none" {...props} />;
};

return (
<BottomSheet
backdropComponent={renderBackdrop}
backdropComponent={isLoadingSignContract ? renderUncloseableBackdrop : renderBackdrop}
ref={bottomSheetRef}
index={-1}
snapPoints={snapPoints}
animateOnMount={reducedMotion ? false : true}
enableContentPanningGesture={false}
enablePanDownToClose={!isLoadingSignContract}
enableHandlePanningGesture={!isLoadingSignContract}
handleComponent={isLoadingSignContract ? null : BottomSheetHandle}
>
<BottomSheetView style={[styles.bottomSheetContainer, { paddingBottom: insets.bottom }]}>
{!isFinishedSigning.isFinished ? (
Expand Down
2 changes: 2 additions & 0 deletions mobile/src/screens/CreateUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const schema = yup.object({
value: '50',
})}`,
),
birthday: yup.date().required(`${i18n.t('register:create_user.form.birthday.required')}`),
});

const CreateUser = ({ navigation }: any) => {
Expand Down Expand Up @@ -192,6 +193,7 @@ const CreateUser = ({ navigation }: any) => {
disabled={isLoading}
name="birthday"
error={errors.birthday}
required={true}
/>
<FormSelect
control={control as any}
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/screens/IdentityData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const IdentityData = ({ navigation, route }: any) => {
const [isUserOver16, setIsUserOver16] = useState(
userProfile?.birthday
? isOver16(userProfile?.birthday)
: userProfile?.userPersonalData.cnp
: userProfile?.userPersonalData
? isOver16FromCNP(userProfile?.userPersonalData.cnp)
: true,
);
Expand Down
Loading

0 comments on commit 8519415

Please sign in to comment.