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 3, 2024
2 parents f096aaa + fb9f052 commit 7f7cdd5
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export class DocumentContractRepositoryService extends RepositoryWithPagination<
.andWhere('EXTRACT(YEAR FROM contract.documentDate) = :year', {
year: documentDate.getFullYear(),
})
.andWhere('contract.status NOT IN (:...statuses)', {
statuses: [
DocumentContractStatus.REJECTED_NGO,
DocumentContractStatus.REJECTED_VOLUNTEER,
],
})
.getMany();

return existingContracts.length > 0;
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,12 @@
"description": "View the list of all your volunteer contracts in VIC. The volunteer contract has a predefined structure. You can create multiple contract templates (e.g. volunteer contract &gt;16 years, volunteer contract &lt;16 years)."
}
},
"document_contract": {
"delete_modal": {
"title": "Are you sure you want to delete this contract?",
"description": "Once deleted, the contract cannot be recovered."
}
},
"popover": {
"edit": "Edit template title",
"download": "Download document",
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/assets/locales/ro/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,12 @@
"description": "Vizualizează lista tuturor contractelor voluntarilor tăi din VIC. Contractul de voluntar are o structura prestabilită. Poți crea mai multe template-uri de contracte (ex. contract pentru voluntari >16 ani, contract pentru voluntari <16 ani)."
}
},
"document_contract": {
"delete_modal": {
"title": "Ești sigur că dorești ștergerea acestui contract?",
"description": "Odată șters, contractul nu mai poate fi recuperat."
}
},
"popover": {
"edit": "Editează titlu template",
"download": "Descarcă document",
Expand Down Expand Up @@ -1288,7 +1294,7 @@
"max_length": "Numărul contractului trebuie să aibă maxim 10 caractere",
"min_length": "Numărul contractului trebuie să aibă minim 1 caracter",
"unique": "Numărul contractului trebuie să fie unic",
"invalid": "Numărul contractului trebuie să fie un număr întreg pozitiv"
"invalid": "Numărul contractului trebuie să fie un număr întreg pozitiv sau zero"
},
"document_period": {
"required": "Perioada contractului este obligatorie",
Expand Down Expand Up @@ -1365,4 +1371,4 @@
"clear": "Șterge",
"apply_all": "Aplică pentru toate"
}
}
}
10 changes: 6 additions & 4 deletions frontend/src/components/AutoFillContractCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ interface AutoFillContractCardProps {
const autoFillValidationSchema = yup.object({
startingNumber: yup
.number()
.positive(`${i18n.t('doc_templates:contract_card_form.document_number.invalid')}`)
.moreThan(-1, `${i18n.t('doc_templates:contract_card_form.document_number.invalid')}`)
.test('min-length', `${i18n.t('doc_templates:contract_card_form.document_number:min_length')}`, (value) => !value || value.toString().length >= 1)
.test('max-length', `${i18n.t('doc_templates:contract_card_form.document_number:max_length')}`, (value) => !value || value.toString().length <= 10)
.typeError(`${i18n.t('doc_templates:contract_card_form.document_number.invalid')}`)
.required(`${i18n.t('doc_templates:contract_card_form.document_number:required')}`),
.required(`${i18n.t('doc_templates:contract_card_form.document_number.required')}`),
documentContractDate: yup
.date()
.required(`${i18n.t('doc_templates:contract_card_form.document_date.required')}`),
Expand Down Expand Up @@ -73,12 +75,12 @@ export const AutoFillContractCard = ({ onSubmit }: AutoFillContractCardProps) =>
return (
<FormInput
label={t('form.starting_number')}
value={value ?? ''}
value={value}
onChange={onChange}
placeholder="Introdu numarul"
wrapperClassname="flex-1 justify-between"
type="number"
errorMessage={errors.startingNumber ? t('required', { ns: 'general' }) : ''}
errorMessage={errors.startingNumber?.message}
/>
);
}}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/DocumentContractsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ const DocumentContractsTable = ({ query, setQuery }: DocumentContractsTableBasic
/>
{selectedDeleteContract && (
<ConfirmationModal
title={t('contract.delete_modal.title')}
description={t('contract.delete_modal.description')}
title={t('document_contract.delete_modal.title')}
description={t('document_contract.delete_modal.description')}
confirmBtnLabel={t('general:delete')}
onClose={setSelectedDeleteContract.bind(null, null)}
onConfirm={confirmDelete}
Expand Down
12 changes: 11 additions & 1 deletion mobile/src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,17 @@
"approved_start": "Your contract with",
"approved_end": "has been approved and signed.",
"rejected_start": "Your contract with",
"rejected_end": "was rejected. See reason."
"rejected_end": "was rejected by the organization. See reason.",
"rejected_volunteer_start": "You rejected the contract with",
"rejected_volunteer_end": ".",
"validated_start": "Your contract with",
"validated_end": "has been validated by the organization.",
"signed_start": "Your contract with",
"signed_end": "has been signed by the organization representative.",
"signed_volunteer_start": "You signed the contract with",
"signed_volunteer_end": ".",
"deleted_start": "Your contract with",
"deleted_end": "has been deleted."
},
"organization": {
"request": "Application to join the organization",
Expand Down
12 changes: 11 additions & 1 deletion mobile/src/assets/locales/ro/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,17 @@
"approved_start": "Contractul tău cu",
"approved_end": "a fost aprobat și semnat.",
"rejected_start": "Contractul tău cu",
"rejected_end": "a fost respins. Vezi motiv."
"rejected_end": "a fost respins de către organizație. Vezi motivul.",
"rejected_volunteer_start": "Ai respins contractul cu",
"rejected_volunteer_end": ".",
"validated_start": "Contractul tău cu",
"validated_end": "a fost validat de către organizație. Urmează să fie semnat de către reprezentantul acesteia.",
"signed_start": "Contractul tău cu",
"signed_end": "a fost semnat de către reprezentantul organizației.",
"signed_volunteer_start": "Ai semnat contractul cu",
"signed_volunteer_end": ".",
"deleted_start": "Contractul tău cu",
"deleted_end": "a fost șters."
},
"organization": {
"request": "Cererea de înscriere în organizația",
Expand Down
1 change: 1 addition & 0 deletions mobile/src/common/enums/tracked-event-name.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum TrackedEventName {
APPROVE_CONTRACT = 'APPROVE_CONTRACT',
REJECT_CONTRACT = 'REJECT_CONTRACT',

// Document Contract - new implementation
CREATE_DOCUMENT_CONTRACT = 'CREATE_DOCUMENT_CONTRACT',
VALIDATE_DOCUMENT_CONTRACT = 'VALIDATE_DOCUMENT_CONTRACT',
SIGN_DOCUMENT_CONTRACT_BY_NGO = 'SIGN_DOCUMENT_CONTRACT_BY_NGO',
Expand Down
9 changes: 5 additions & 4 deletions mobile/src/screens/DocumentsContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PageLayout from '../layouts/PageLayout';
import { useTranslation } from 'react-i18next';
import { usePaddingTop } from '../hooks/usePaddingTop';
import { Text, useTheme } from '@ui-kitten/components';
import { IDocumentContract, RejectionReason } from '../services/documents/documents.api';
import { RejectionReason } from '../services/documents/documents.api';
import { DocumentContractStatus } from '../common/enums/document-contract-status.enum';
import Disclaimer from '../components/Disclaimer';
import { useUserProfile } from '../store/profile/profile.selector';
Expand Down Expand Up @@ -48,11 +48,12 @@ export const DocumentsContract = ({ navigation, route }: any) => {
const [isSignatureEmpty, setIsSignatureEmpty] = useState(false);

// queries
const { contract: routeContract } = route.params as { contract: IDocumentContract };
const { contractId } = route.params;
const { data: contract, isLoading: isLoadingContract } = useGetContractQuery(
routeContract.documentId,
contractId,
userProfile?.activeOrganization?.id,
);

const { mutate: signContract, isLoading: isLoadingSignContract } = useSignContractMutation();

const isUserOver16 = useMemo(
Expand Down Expand Up @@ -249,7 +250,7 @@ export const DocumentsContract = ({ navigation, route }: any) => {
return (
<PageLayout
onBackButtonPress={navigation.goBack}
title={t('contract.title', { value: routeContract.documentNumber })}
title={t('contract.title', { value: '' })}
headerStyle={{ paddingTop }}
>
<View style={styles.container}>
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/screens/DocumentsContracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const DocumentsContracts = ({ navigation }: any) => {
}

const onContractPress = (contract: IDocumentContract) => {
navigation.navigate('documents/contract', { contract });
navigation.navigate('documents/contract', { contractId: contract.documentId });
};

return (
Expand Down
90 changes: 78 additions & 12 deletions mobile/src/screens/News.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,76 @@ const News = ({ navigation, route }: any) => {
);
}

if (item.eventName === TrackedEventName.CREATE_DOCUMENT_CONTRACT) {
return (
<NewsContent
startText={''}
organizationName={item.organizationName}
endText={`${t('item.documents.new')}`}
/>
);
}

if (item.eventName === TrackedEventName.VALIDATE_DOCUMENT_CONTRACT) {
return (
<NewsContent
startText={`${t('item.documents.validated_start')}`}
organizationName={item.organizationName}
endText={`${t('item.documents.validated_end')}`}
/>
);
}

if (item.eventName === TrackedEventName.SIGN_DOCUMENT_CONTRACT_BY_NGO) {
return (
<NewsContent
startText={`${t('item.documents.signed_start')}`}
organizationName={item.organizationName}
endText={`${t('item.documents.signed_end')}`}
/>
);
}

if (item.eventName === TrackedEventName.SIGN_DOCUMENT_CONTRACT_BY_VOLUNTEER) {
return (
<NewsContent
startText={`${t('item.documents.signed_start')}`}
organizationName={item.organizationName}
endText={`${t('item.documents.signed_end')}`}
/>
);
}

if (item.eventName === TrackedEventName.REJECT_DOCUMENT_CONTRACT_BY_NGO) {
return (
<NewsContent
startText={`${t('item.documents.rejected_start')}`}
organizationName={item.organizationName}
endText={`${t('item.documents.rejected_end')}`}
/>
);
}

if (item.eventName === TrackedEventName.REJECT_DOCUMENT_CONTRACT_BY_VOLUNTEER) {
return (
<NewsContent
startText={`${t('item.documents.rejected_volunteer_start')}`}
organizationName={item.organizationName}
endText={`${t('item.documents.rejected_volunteer_end')}`}
/>
);
}

if (item.eventName === TrackedEventName.DELETE_DOCUMENT_CONTRACT) {
return (
<NewsContent
startText={`${t('item.documents.deleted_start')}`}
organizationName={item.organizationName}
endText={`${t('item.documents.deleted_end')}`}
/>
);
}

return <></>;
};

Expand Down Expand Up @@ -198,13 +268,11 @@ const News = ({ navigation, route }: any) => {
}

if (type === NewsType.CONTRACTS) {
if (item.eventName === TrackedEventName.REJECT_CONTRACT) {
navigation.navigate('rejected-contract', {
contractId: item.contractId,
});
} else {
navigation.navigate('documents', { volunteerId: activeOrganization?.volunteerId });
// don't navigate to contract if it was deleted
if (item.eventName === TrackedEventName.DELETE_DOCUMENT_CONTRACT) {
return;
}
navigation.navigate('documents/contract', { contractId: item.contractId });
}

if (type === NewsType.ORGANIZATIONS) {
Expand All @@ -220,13 +288,11 @@ const News = ({ navigation, route }: any) => {
}

if (type === NewsType.CONTRACTS) {
if (item.eventName === TrackedEventName.REJECT_CONTRACT) {
navigation.navigate('rejected-contract', {
contractId: item.contractId,
});
} else {
navigation.navigate('documents', {});
// don't navigate to contract if it was deleted
if (item.eventName === TrackedEventName.DELETE_DOCUMENT_CONTRACT) {
return;
}
navigation.navigate('documents/contract', { contractId: item.contractId });
}

if (type === NewsType.ORGANIZATIONS) {
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/services/documents/documents.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const getContract = (
contractId: string,
organizationId: string,
): Promise<IDocumentContract> => {
const params = { contractId, organizationId };
const params = { organizationId };
return API.get(`/mobile/documents/contracts/${contractId}`, {
params,
}).then((res) => res.data);
Expand Down

0 comments on commit 7f7cdd5

Please sign in to comment.