1
1
import React from 'react' ;
2
- import { Form , Button , Input , DatePicker , Space } from 'antd' ;
2
+ import { Form , Button , Input , DatePicker , Space , Switch } from 'antd' ;
3
3
import { SelectProps } from 'antd/lib/select' ;
4
4
import { AsyncSelectProps , formItemLayout , tailLayout } from '@opensrp/react-utils' ;
5
5
import { useTranslation } from '../../mls' ;
@@ -12,7 +12,7 @@ import {
12
12
sendInfoNotification ,
13
13
} from '@opensrp/notifications' ;
14
14
import {
15
- productName ,
15
+ product ,
16
16
quantity ,
17
17
deliveryDate ,
18
18
accountabilityEndDate ,
@@ -24,18 +24,31 @@ import {
24
24
groupResourceType ,
25
25
valuesetResourceType ,
26
26
UNICEF_SECTION_ENDPOINT ,
27
+ id ,
28
+ identifier ,
29
+ active ,
30
+ name ,
31
+ type ,
32
+ actual ,
27
33
} from '../../constants' ;
28
34
import { groupSelectfilterFunction , SelectOption } from '../ProductForm/utils' ;
29
35
import { FHIRServiceClass , AsyncSelect } from '@opensrp/react-utils' ;
30
36
import { IValueSet } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IValueSet' ;
31
- import { getValuesetSelectOptions , projectOptions } from './utils' ;
37
+ import {
38
+ getLocationInventoryPayload ,
39
+ getValuesetSelectOptions ,
40
+ handleDisabledFutureDates ,
41
+ handleDisabledPastDates ,
42
+ projectOptions ,
43
+ } from './utils' ;
32
44
import { IBundle } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IBundle' ;
45
+ import { GroupFormFields } from './types' ;
33
46
34
47
const { Item : FormItem } = Form ;
35
48
36
49
export interface LocationInventoryFormProps {
37
50
fhirBaseURL : string ;
38
- initialValues : Dictionary ;
51
+ initialValues : GroupFormFields ;
39
52
disabled : string [ ] ;
40
53
cancelUrl ?: string ;
41
54
successUrl ?: string ;
@@ -62,7 +75,8 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
62
75
const queryClient = useQueryClient ( ) ;
63
76
64
77
const { mutate, isLoading } = useMutation (
65
- ( values : Dictionary ) => {
78
+ ( values : GroupFormFields ) => {
79
+ const payload = getLocationInventoryPayload ( values ) ;
66
80
return postLocationInventory ( fhirBaseURL , values ) ;
67
81
} ,
68
82
{
@@ -84,7 +98,7 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
84
98
label : t ( 'UNICEF section' ) ,
85
99
optionsGetter : getValuesetSelectOptions ,
86
100
selectProps : {
87
- placeholder : t ( 'Select section' ) ,
101
+ placeholder : t ( 'Select UNICEF section' ) ,
88
102
showSearch : true ,
89
103
filterOption : groupSelectfilterFunction as SelectProps < SelectOption [ ] > [ 'filterOption' ] ,
90
104
} ,
@@ -118,7 +132,7 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
118
132
119
133
const projectsSelectProps : AsyncSelectProps < IBundle > = {
120
134
id : 'project' ,
121
- name : productName ,
135
+ name : product ,
122
136
label : t ( 'Product name' ) ,
123
137
optionsGetter : projectOptions ,
124
138
selectProps : {
@@ -137,40 +151,31 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
137
151
< Form
138
152
requiredMark = { false }
139
153
{ ...formItemLayout }
140
- onFinish = { ( values : Dictionary ) => {
154
+ onFinish = { ( values : GroupFormFields ) => {
141
155
mutate ( values ) ;
142
156
} }
143
157
initialValues = { initialValues }
144
158
>
145
- { /* <FormItem id="productName" name={productName} label={t('Product name')}>
146
- <Select
147
- placeholder={t('Select product')}
148
- options={projectOptions}
149
- showSearch={true}
150
- filterOption={groupSelectfilterFunction as SelectProps<SelectOption[]>['filterOption']}
151
- />
152
- </FormItem> */ }
153
-
154
159
< AsyncSelect { ...projectsSelectProps } />
155
160
156
161
< FormItem id = "quantity" name = { quantity } label = { t ( 'Quantity (Optional)' ) } >
157
162
< Input required = { false } type = "number" />
158
163
</ FormItem >
159
164
160
165
< FormItem id = "deliveryDate" name = { deliveryDate } label = { t ( 'Delivery date' ) } >
161
- < DatePicker />
166
+ < DatePicker disabledDate = { handleDisabledFutureDates } />
162
167
</ FormItem >
163
168
164
169
< FormItem
165
170
id = "accounterbilityEndDate"
166
171
name = { accountabilityEndDate }
167
172
label = { t ( 'Accountability end date' ) }
168
173
>
169
- < DatePicker />
174
+ < DatePicker disabledDate = { handleDisabledPastDates } />
170
175
</ FormItem >
171
176
172
177
< FormItem id = "expiryDate" name = { expiryDate } label = { t ( 'Expiry date (Optional)' ) } >
173
- < DatePicker />
178
+ < DatePicker disabledDate = { handleDisabledPastDates } />
174
179
</ FormItem >
175
180
176
181
< AsyncSelect { ...unicefSectionProps } />
@@ -185,6 +190,27 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
185
190
< Input type = "number" />
186
191
</ FormItem >
187
192
193
+ { /* start hidden fields */ }
194
+ < FormItem hidden = { true } id = "id" name = { id } label = { t ( 'Commodity Id' ) } >
195
+ < Input disabled = { true } />
196
+ </ FormItem >
197
+ < FormItem hidden = { true } id = "identifier" name = { identifier } label = { t ( 'Identifier' ) } >
198
+ < Input disabled = { true } />
199
+ </ FormItem >
200
+ < FormItem hidden = { true } id = "active" name = { active } label = { t ( 'Active' ) } >
201
+ < Switch checked = { initialValues . active } disabled = { true } />
202
+ </ FormItem >
203
+ < FormItem hidden = { true } id = "actual" name = { actual } label = { t ( 'Actual' ) } >
204
+ < Switch checked = { initialValues . actual } disabled = { true } />
205
+ </ FormItem >
206
+ < FormItem hidden = { true } id = "name" name = { name } label = { t ( 'Name' ) } >
207
+ < Input disabled = { true } />
208
+ </ FormItem >
209
+ < FormItem hidden = { true } id = "type" name = { type } label = { t ( 'Type' ) } >
210
+ < Input disabled = { true } />
211
+ </ FormItem >
212
+ { /* End hidden fields */ }
213
+
188
214
< FormItem { ...tailLayout } >
189
215
< Space >
190
216
{ /* todo: might remove cancel btn */ }
0 commit comments