Skip to content

Commit

Permalink
Merge branch 'feature/contracts' of github.com:code4romania/teo into …
Browse files Browse the repository at this point in the history
…feature/contracts
  • Loading branch information
radulescuandrew committed Sep 23, 2024
2 parents fc49240 + 2af2de6 commit 485a164
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React, { useState } from 'react';
import { InfoParagraph } from '../InfoParagraph';
import { ContractTerms } from './ContractTerms';
import { useTranslation } from 'react-i18next';
import { Signatures } from '../Signatures';
import { useOrganizationQuery } from '../../services/organization/organization.service';
import LoadingContent from '../LoadingContent';
import { OrganizationDataError } from '../OrganizationDataError';
import { Control, FieldErrors, FieldValues, UseFormGetValues, UseFormReset } from 'react-hook-form';
import { Signatures } from '../Signatures';

export const ContractTemplatePreview = ({
control,
Expand Down
53 changes: 34 additions & 19 deletions frontend/src/pages/GenerateContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export const GenerateContract = () => {
if (!volunteersData || !volunteersData[volunteer.id]) {
return;
}

await addDocumentContract({
documentTemplateId: selectedTemplate?.id as string,
volunteerId: volunteer.id,
Expand Down Expand Up @@ -185,7 +184,7 @@ export const GenerateContract = () => {
// if we have errors -> close the modal and keep in the list only the volunteers with errors

// keep only the volunteers with errors in the list
if (contractsWithErrors) {
if (contractsWithErrors && Object.keys(contractsWithErrors).length > 0) {
const volunteerIdsWithError = Object.keys(contractsWithErrors);
setSelectedVolunteers((selectedVolunteers) => {
return selectedVolunteers.filter((v) => volunteerIdsWithError.includes(v.id));
Expand All @@ -203,6 +202,14 @@ export const GenerateContract = () => {
});
}

// if we have no volunteers with errors -> navigate to all contracts
if (
!contractsWithErrors ||
(contractsWithErrors && Object.keys(contractsWithErrors).length === 0)
) {
navigate('/documents/templates');
}

// reset
setSentContractsCount(0);
// todo: close modal on success and navigate to all contracts
Expand Down Expand Up @@ -255,26 +262,34 @@ export const GenerateContract = () => {
</>
)}
{/* success content */}
{!isLoadingAddDocumentContracts && !contractsWithErrors && (
<div className="flex flex-col gap-4">
<div className="flex flex-row justify-center">
<CheckCircleIcon width={70} height={70} className="text-yellow-500" />
{!isLoadingAddDocumentContracts &&
(!contractsWithErrors || Object.keys(contractsWithErrors).length === 0) && (
<div className="flex flex-col gap-4 items-center pb-4">
<div className="flex flex-row justify-center">
<CheckCircleIcon width={70} height={70} className="text-yellow-500" />
</div>
<p className="text-center">Toate contractele au fost trimise cu succes!</p>
<Button
label="Înapoi la lista de contracte"
onClick={() => navigate('/documents/templates')}
className="btn-primary"
/>
</div>
<p className="text-center">Toate contractele au fost trimise cu succes!</p>
</div>
)}
)}
{/* error content */}
{!isLoadingAddDocumentContracts && contractsWithErrors && (
<div className="flex flex-col gap-2">
<div className="flex flex-row justify-center">
<ExclamationCircleIcon width={70} height={70} className="text-red-400" />
{!isLoadingAddDocumentContracts &&
contractsWithErrors &&
Object.keys(contractsWithErrors).length > 0 && (
<div className="flex flex-col gap-2">
<div className="flex flex-row justify-center">
<ExclamationCircleIcon width={70} height={70} className="text-red-400" />
</div>
<p className="text-center">
{`${t('modal.loading.description', { value1: sentContractsCount, value2: selectedVolunteers.length })}`}
</p>
<p className="text-center">{t('modal.error.description')}</p>
</div>
<p className="text-center">
{`${t('modal.loading.description', { value1: sentContractsCount, value2: selectedVolunteers.length })}`}
</p>
<p className="text-center">{t('modal.error.description')}</p>
</div>
)}
)}
</Modal>
)}
</>
Expand Down

0 comments on commit 485a164

Please sign in to comment.