Skip to content

Commit

Permalink
Merge pull request #304 from app-masters/att-crud-beneficio-data
Browse files Browse the repository at this point in the history
Att crud beneficio data
  • Loading branch information
jfbaraky authored Jun 9, 2020
2 parents de076ac + 31ee0f9 commit 3f5c0df
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 56 deletions.
3 changes: 1 addition & 2 deletions admin/src/interfaces/benefit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ export interface Benefit {
institutionId: number;
groupName: string;
title: string;
month: number;
year: number;
date: Date;
value: keyof typeof familyGroupList;
createdAt?: number | Date | null;
updatedAt?: number | Date | null;
Expand Down
59 changes: 21 additions & 38 deletions admin/src/pages/benefits/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const schema = yup.object().shape({
institutionId: yup.number().label('Instituição').required(),
groupName: yup.string().label('Família').required(),
title: yup.string().label('Nome').required(),
month: yup.number().label('Mês').required(),
year: yup.number().label('Ano').required(),
date: yup.date().label('Data').required(),
value: !showProductList ? yup.string().label('Valor').required() : yup.string().label('Valor').nullable(),
benefitProduct: showProductList
? yup
Expand Down Expand Up @@ -77,7 +76,7 @@ export const BenefitForm: React.FC<RouteComponentProps<{ id: string }>> = (props
institutionId: !institutionLoading && institutionList && institutionList.length > 0 ? institutionList[0].id : 1,
groupName: 'children',
title: '',
month: undefined,
date: undefined,
year: undefined,
value: undefined,
benefitProduct: undefined
Expand All @@ -97,12 +96,13 @@ export const BenefitForm: React.FC<RouteComponentProps<{ id: string }>> = (props

const titleMeta = getFieldMeta('title');
const groupMeta = getFieldMeta('groupName');
const monthMeta = getFieldMeta('month');
const yearMeta = getFieldMeta('year');
const dateMeta = getFieldMeta('year');
const valueMeta = getFieldMeta('value');
const institutionIdMeta = getFieldMeta('institutionId');
const productsMeta = getFieldMeta('benefitProduct');

const monthFormat = 'MM/YYYY';

return (
<Modal
title={isCreating ? 'Criar' : 'Editar'}
Expand All @@ -125,6 +125,22 @@ export const BenefitForm: React.FC<RouteComponentProps<{ id: string }>> = (props
>
<Input id="title" name="title" onChange={handleChange} value={values.title} onPressEnter={submitForm} />
</Form.Item>
<Form.Item
label={'Data'}
validateStatus={!!dateMeta.error && !!dateMeta.touched ? 'error' : ''}
help={!!dateMeta.error && !!dateMeta.touched ? dateMeta.error : undefined}
>
<DatePicker
locale={locale}
picker="month"
style={{ width: '100%' }}
format={monthFormat}
defaultValue={values.date ? moment(values.date) : undefined}
onChange={(date) => {
setFieldValue('date', date);
}}
/>
</Form.Item>

<Form.Item
label={'Instituição'}
Expand Down Expand Up @@ -179,39 +195,6 @@ export const BenefitForm: React.FC<RouteComponentProps<{ id: string }>> = (props
</Select>
</Form.Item>

<Row gutter={[16, 16]}>
<Col span={12}>
<Form.Item
label={'Mês'}
validateStatus={!!monthMeta.error && !!monthMeta.touched ? 'error' : ''}
help={!!monthMeta.error && !!monthMeta.touched ? monthMeta.error : undefined}
>
<DatePicker.MonthPicker
format={'MMMM'}
locale={locale}
style={{ width: '100%' }}
defaultValue={values.month ? moment(values.month, 'MM') : undefined}
onChange={(date) => setFieldValue('month', Number(date?.format('MM')))}
/>
</Form.Item>
</Col>
<Col span={12}>
<Form.Item
label={'Ano'}
validateStatus={!!yearMeta.error && !!yearMeta.touched ? 'error' : ''}
help={!!yearMeta.error && !!yearMeta.touched ? yearMeta.error : undefined}
>
<DatePicker.YearPicker
format={'YYYY'}
locale={locale}
style={{ width: '100%' }}
defaultValue={values.year ? moment(values.year, 'YYYY') : undefined}
onChange={(date) => setFieldValue('year', Number(date?.format('YYYY')))}
/>
</Form.Item>
</Col>
</Row>

{/* Value per dependent should only be shown when the TYPE is `ticket` */}
{!showProductList && (
<Form.Item
Expand Down
17 changes: 2 additions & 15 deletions admin/src/pages/benefits/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,9 @@ export const BenefitList: React.FC<{}> = () => {
dataIndex="groupName"
render={(data: Benefit['groupName']) => familyGroupList[data]?.title || data}
/>
<Table.Column title="Mês" dataIndex="month" />
<Table.Column title="Ano" dataIndex="year" />
<Table.Column title="Data" dataIndex="date" render={(data) => moment(data).format('MM/YYYY')} />
{/* Show the product list column depending on the type of benefit */}
{showProductList ? (
<Table.Column
title="Produtos"
dataIndex="benefitProduct"
render={(data: Benefit['benefitProduct']) =>
data?.map((product) => (
<div key={product.productsId}>{`${product.amount}x ${
productList.find((p) => p.id === product.productsId)?.name
}`}</div>
))
}
/>
) : (
{!showProductList && (
<Table.Column
title="Valor por dependente"
dataIndex="value"
Expand Down
1 change: 0 additions & 1 deletion backend/src/models/consumptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export const getFamilyDependentBalanceTicket = async (family: Family, availableB
for (const benefit of availableBenefits) {
const benefitDate = moment(benefit.date as Date);
if (benefit.groupName !== family.groupName) continue; // Don't check if it's from another group

// Check all the dates
const notInFuture = benefitDate.toDate() <= todayDate.endOf('month').toDate();
const afterCreation = benefitDate.toDate() >= startDate.startOf('month').toDate();
Expand Down

0 comments on commit 3f5c0df

Please sign in to comment.