Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OM-86: generic voucher acquirement, overall adjustments #6

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions src/components/AcquirementGenericVoucherForm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
import React from 'react';

function AcquirementGenericVoucherForm() {
import { Grid, Divider } from '@material-ui/core';

import { NumberInput, TextInput } from '@openimis/fe-core';
import { VOUCHER_QUANTITY_THRESHOLD } from '../constants';

function AcquirementGenericVoucherForm({
classes, readOnly = false, edited, onEditedChange, formatMessage,
}) {
return (
<div> AcquirementGenericVoucherForm </div>
<>
<Grid container direction="row">
<Grid item xs={3} className={classes.item}>
<NumberInput
module="workerVoucher"
label="workerVoucher.acquire.vouchersQuantity"
value={edited?.quantity}
onChange={(quantity) => onEditedChange({ ...edited, quantity })}
required
max={VOUCHER_QUANTITY_THRESHOLD}
readOnly={readOnly}
/>
</Grid>
</Grid>
<Divider style={{ margin: '12px 0' }} />
<Grid container xs={12}>
<Grid item xs={3} className={classes.item}>
<TextInput
module="workerVoucher"
label="workerVoucher.employer.code"
value={edited?.employer?.code ?? formatMessage('workerVoucher.WorkerDateRangePicker.notAvailable')}
readOnly
/>
</Grid>
<Grid item xs={3} className={classes.item}>
<TextInput
module="workerVoucher"
label="workerVoucher.employer.tradename"
value={edited?.employer?.code ?? formatMessage('workerVoucher.WorkerDateRangePicker.notAvailable')}
readOnly
/>
</Grid>
</Grid>
<Divider style={{ margin: '12px 0' }} />
</>
);
}

Expand Down
3 changes: 0 additions & 3 deletions src/components/VoucherAcquirementForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export const useStyles = makeStyles((theme) => ({
paperHeaderTitle: theme.paper.title,
tableTitle: theme.table.title,
item: theme.paper.item,
fullHeight: {
height: '100%',
},
}));

function VoucherAcquirementForm() {
Expand Down
38 changes: 29 additions & 9 deletions src/components/VoucherAcquirementGenericVoucher.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';

import {
Divider, Grid, Typography, Button, Tooltip,
} from '@material-ui/core';
import { makeStyles } from '@material-ui/styles';

import { useModulesManager, useTranslations } from '@openimis/fe-core';
import { MODULE_NAME } from '../constants';
import { MODULE_NAME, USER_ECONOMIC_UNIT_STORAGE_KEY, VOUCHER_QUANTITY_THRESHOLD } from '../constants';
import AcquirementGenericVoucherForm from './AcquirementGenericVoucherForm';

export const useStyles = makeStyles((theme) => ({
Expand All @@ -19,9 +19,6 @@ export const useStyles = makeStyles((theme) => ({
},
tableTitle: theme.table.title,
item: theme.paper.item,
fullHeight: {
height: '100%',
},
}));

function VoucherAcquirementGenericVoucher() {
Expand All @@ -30,20 +27,43 @@ function VoucherAcquirementGenericVoucher() {
const { formatMessage } = useTranslations(MODULE_NAME, modulesManager);
const [voucherAcquirement, setVoucherAcquirement] = useState({});

const canAcquire = (voucherAcquirement) => !voucherAcquirement?.quantity
|| voucherAcquirement?.quantity > VOUCHER_QUANTITY_THRESHOLD;

const onVoucherAcquire = () => {
// TODO: Open Payment modal
console.log(voucherAcquirement);
};

useEffect(() => {
const storedUserEconomicUnit = localStorage.getItem(USER_ECONOMIC_UNIT_STORAGE_KEY);

if (storedUserEconomicUnit) {
const userEconomicUnit = JSON.parse(storedUserEconomicUnit);

setVoucherAcquirement((prevState) => ({ ...prevState, employer: userEconomicUnit }));
}
}, [setVoucherAcquirement]);

return (
<>
<Grid xs={12}>
<Grid container className={classes.paperHeaderTitle}>
<Typography variant="h5">{formatMessage('workerVoucher.acquirement.method.GENERIC_VOUCHER')}</Typography>
<Tooltip title={formatMessage('workerVoucher.acquire.voucher.specificWorkers')}>
<Button variant="outlined" style={{ border: 0 }} onClick={onVoucherAcquire}>
{formatMessage('workerVoucher.acquire.voucher')}
</Button>
<Tooltip title={canAcquire(voucherAcquirement)
? formatMessage('workerVoucher.acquire.vouchers.required')
: formatMessage('workerVoucher.acquire.vouchers')}
>
<span>
<Button
variant="outlined"
style={{ border: 0 }}
onClick={onVoucherAcquire}
disabled={canAcquire(voucherAcquirement)}
>
<Typography variant="subtitle1">{formatMessage('workerVoucher.acquire.voucher')}</Typography>
</Button>
</span>
</Tooltip>
</Grid>
</Grid>
Expand Down
24 changes: 17 additions & 7 deletions src/components/VoucherAcquirementSpecificWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export const useStyles = makeStyles((theme) => ({
},
tableTitle: theme.table.title,
item: theme.paper.item,
fullHeight: {
height: '100%',
},
}));

function VoucherAcquirementSpecificWorker() {
Expand All @@ -30,6 +27,9 @@ function VoucherAcquirementSpecificWorker() {
const { formatMessage } = useTranslations(MODULE_NAME, modulesManager);
const [voucherAcquirement, setVoucherAcquirement] = useState({});

const canAcquire = (voucherAcquirement) => !voucherAcquirement?.workers?.length
|| !voucherAcquirement?.dateRanges?.length;

const onVoucherAcquire = () => {
// TODO: Open Payment modal
console.log(voucherAcquirement);
Expand All @@ -50,10 +50,20 @@ function VoucherAcquirementSpecificWorker() {
<Grid xs={12}>
<Grid container className={classes.paperHeaderTitle}>
<Typography variant="h5">{formatMessage('workerVoucher.acquirement.method.SPECIFIC_WORKER')}</Typography>
<Tooltip title={formatMessage('workerVoucher.acquire.voucher.specificWorkers')}>
<Button variant="outlined" style={{ border: 0 }} onClick={onVoucherAcquire}>
{formatMessage('workerVoucher.acquire.voucher')}
</Button>
<Tooltip title={canAcquire(voucherAcquirement)
? formatMessage('workerVoucher.acquire.vouchers.required')
: formatMessage('workerVoucher.acquire.vouchers')}
>
<span>
<Button
variant="outlined"
style={{ border: 0 }}
onClick={onVoucherAcquire}
disabled={canAcquire(voucherAcquirement)}
>
<Typography variant="subtitle1">{formatMessage('workerVoucher.acquire.voucher')}</Typography>
</Button>
</span>
</Tooltip>
</Grid>
</Grid>
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const ROWS_PER_PAGE_OPTIONS = [10, 20, 50, 100];
export const EMPTY_STRING = '';
export const CONTAINS_LOOKUP = 'Icontains';
export const WORKER_THRESHOLD = 3;
export const VOUCHER_QUANTITY_THRESHOLD = 1000;
export const USER_ECONOMIC_UNIT_STORAGE_KEY = 'userEconomicUnit';

const WORKER_VOUCHER_STATUS = {
Expand Down
31 changes: 23 additions & 8 deletions src/pickers/WorkerDateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { PublishedComponent, useTranslations, useModulesManager } from '@openimi
import { MODULE_NAME } from '../constants';

function WorkerDateRangePicker({
classes, readOnly, value, onChange, required,
classes, readOnly, value, onChange,
}) {
const modulesManager = useModulesManager();
const { formatMessage } = useTranslations(MODULE_NAME, modulesManager);
Expand Down Expand Up @@ -60,7 +60,6 @@ function WorkerDateRangePicker({
value={startDate}
onChange={handleStartDateChange}
readOnly={readOnly}
required={required}
// NOTE: maxDate cannot be passed if endDate does not exist.
// Passing any other falsy value will block months manipulation.
// eslint-disable-next-line react/jsx-props-no-spreading
Expand All @@ -75,7 +74,6 @@ function WorkerDateRangePicker({
value={endDate}
onChange={handleEndDateChange}
readOnly={readOnly}
required={required}
// NOTE: minDate cannot be passed if startDate does not exist.
// Passing any other falsy value will block months manipulation.
// eslint-disable-next-line react/jsx-props-no-spreading
Expand All @@ -84,13 +82,27 @@ function WorkerDateRangePicker({
</Grid>
</Grid>
<Grid className={classes.item}>
<Button variant="contained" color="primary" onClick={addDateRange} disabled={!startDate || !endDate}>
{formatMessage('workerVoucher.WorkerDateRangePicker.addButton')}
</Button>
{
!startDate || !endDate ? (
<Tooltip title={formatMessage('workerVoucher.WorkerDateRangePicker.noDates')}>
<span>
<Button variant="contained" color="primary" onClick={addDateRange} disabled={!startDate || !endDate}>
{formatMessage('workerVoucher.WorkerDateRangePicker.addButton')}
</Button>
</span>
</Tooltip>
) : (
<span>
<Button variant="contained" color="primary" onClick={addDateRange} disabled={!startDate || !endDate}>
{formatMessage('workerVoucher.WorkerDateRangePicker.addButton')}
</Button>
</span>
)
}
</Grid>
</Grid>
<Grid container xs={8} style={{ padding: '0 10px 0 0' }}>
<Grid xs={12}>
<Grid xs={12} style={{ margin: '0 0 0 12px' }}>
<Typography variant="subtitle1" style={{ padding: '10px 0 0 0' }}>
{formatMessage('workerVoucher.WorkerDateRangePicker.dateRanges')}
</Typography>
Expand All @@ -105,7 +117,10 @@ function WorkerDateRangePicker({
<DateRangeIcon />
</Avatar>
</ListItemAvatar>
<ListItemText primary="Date Range" secondary={`${range.start} | ${range.end}`} />
<ListItemText
primary={formatMessage('workerVoucher.WorkerDateRangePicker.dateRange')}
secondary={`${range.start} | ${range.end}`}
/>
<ListItemSecondaryAction>
<Tooltip title={formatMessage('workerVoucher.WorkerDateRangePicker.deleteRange')}>
<IconButton
Expand Down
6 changes: 5 additions & 1 deletion src/pickers/WorkerMultiplePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ function WorkerMultiplePicker({
label={formatMessage('workerVoucher.workers')}
readOnly={readOnly}
placeholder={formatMessage('workerVoucher.WorkerMultiplePicker.placeholder')}
noOptionsText={formatMessage('workerVoucher.WorkerMultiplePicker.noOptions')}
noOptionsText={searchString.length < WORKER_THRESHOLD
? formatMessage('workerVoucher.WorkerMultiplePicker.underThreshold')
: formatMessage('workerVoucher.WorkerMultiplePicker.noOptions')}
filterOptions={filtersOptions}
getOptionLabel={({ chfId, lastName, otherNames }) => `${chfId} ${lastName} ${otherNames}`}
filterSelectedOptions={filterSelectedOptions}
Expand All @@ -85,6 +87,8 @@ function WorkerMultiplePicker({
setSearchString('');
}
}}
// TODO: Enable when BE will be ready
disabled
/>
)}
label={formatMessage('workerVoucher.WorkerMultiplePicker.checkbox.label')}
Expand Down
11 changes: 8 additions & 3 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@
"workerVoucher.acquirement.method.GENERIC_VOUCHER": "Generic Voucher",
"workerVoucher.acquirement.method.SPECIFIC_WORKER": "Specific Workers",
"workerVoucher.acquire.voucher": "ACQUIRE VOUCHER",
"workerVoucher.acquire.voucher.specificWorkers": "Acquire Vouchers",
"workerVoucher.acquire.vouchersQuantity": "Quantity of Vouchers",
"workerVoucher.acquire.vouchers": "Acquire Vouchers",
"workerVoucher.acquire.vouchers.required": "You need to fill out all required fields to continue",
"workerVoucher.WorkerMultiplePicker.placeholder": "Search for Worker",
"workerVoucher.WorkerMultiplePicker.noOptions": "Enter at least 3 characters of National ID",
"workerVoucher.WorkerMultiplePicker.underThreshold": "Enter at least 3 characters of National ID",
"workerVoucher.WorkerMultiplePicker.noOptions": "Worker not found",
"workerVoucher.WorkerMultiplePicker.checkbox.label": "Show only workers I've previously worked with",
"workerVoucher.WorkerDateRangePicker.startDate": "Start Date",
"workerVoucher.WorkerDateRangePicker.endDate": "End Date",
"workerVoucher.WorkerDateRangePicker.addButton": "Add Date Range",
"workerVoucher.WorkerDateRangePicker.noDates": "To add a Range you need to fill Start Date and End Date",
"workerVoucher.WorkerDateRangePicker.deleteRange": "Delete Date Range",
"workerVoucher.WorkerDateRangePicker.dateRanges": "Date Ranges:",
"workerVoucher.WorkerDateRangePicker.dateRange": "Date Range",
"workerVoucher.WorkerDateRangePicker.dateRanges": "Date Ranges: *",
"workerVoucher.WorkerDateRangePicker.noRanges": "No date ranges registered",
"workerVoucher.WorkerDateRangePicker.notAvailable": "NOT AVAILABLE"
}
Loading