-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2069de
commit b7b5c1c
Showing
24 changed files
with
4,007 additions
and
3,083 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
packages/fhir-group-management/src/components/CommodityAddEdit/Default/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
import { CommodityForm } from '../../ProductForm'; | ||
import { useParams } from 'react-router'; | ||
import { accountabilityPeriod, appropriateUsage, availability, condition, groupResourceType, isAttractiveItem, LIST_COMMODITY_URL, materialNumber, productImage } from '../../../constants'; | ||
Check failure on line 5 in packages/fhir-group-management/src/components/CommodityAddEdit/Default/index.tsx GitHub Actions / test (16.17.0, ubuntu-latest)
|
||
import { Spin } from 'antd'; | ||
import { PageHeader } from '@opensrp/react-utils'; | ||
import { useQuery } from 'react-query'; | ||
import { FHIRServiceClass, BrokenPage } from '@opensrp/react-utils'; | ||
import { IGroup } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IGroup'; | ||
import { generateGroupPayload, getGroupFormFields, postPutGroup, updateListReferencesFactory, validationRulesFactory } from './utils'; | ||
Check failure on line 11 in packages/fhir-group-management/src/components/CommodityAddEdit/Default/index.tsx GitHub Actions / test (16.17.0, ubuntu-latest)
|
||
import { useTranslation } from '../../../mls'; | ||
|
||
export interface GroupAddEditProps { | ||
fhirBaseURL: string; | ||
listId: string; | ||
} | ||
|
||
export interface RouteParams { | ||
id?: string; | ||
} | ||
|
||
export const CommodityAddEdit = (props: GroupAddEditProps) => { | ||
const { fhirBaseURL: fhirBaseUrl, listId } = props; | ||
|
||
const { id: resourceId } = useParams<RouteParams>(); | ||
const { t } = useTranslation(); | ||
|
||
const groupQuery = useQuery( | ||
[groupResourceType, resourceId], | ||
async () => | ||
new FHIRServiceClass<IGroup>(fhirBaseUrl, groupResourceType).read(resourceId as string), | ||
{ | ||
enabled: !!resourceId, | ||
} | ||
); | ||
|
||
if (!groupQuery.isIdle && groupQuery.isLoading) { | ||
return <Spin size="large" className="custom-spinner"></Spin>; | ||
} | ||
|
||
if (groupQuery.error && !groupQuery.data) { | ||
return <BrokenPage errorMessage={(groupQuery.error as Error).message} />; | ||
} | ||
|
||
const initialValues = getGroupFormFields(groupQuery.data); | ||
|
||
const pageTitle = groupQuery.data | ||
? t('Edit Commodity | {{name}}', { name: groupQuery.data.name ?? '' }) | ||
: t('Create Commodity'); | ||
|
||
const postSuccess = updateListReferencesFactory(fhirBaseUrl, listId); | ||
|
||
return ( | ||
<section className="content-section"> | ||
<Helmet> | ||
<title>{pageTitle}</title> | ||
</Helmet> | ||
<PageHeader title={pageTitle} /> | ||
<div className="bg-white p-5"> | ||
<CommodityForm | ||
hidden={[materialNumber, isAttractiveItem, availability, condition, appropriateUsage, accountabilityPeriod, productImage]} | ||
Check failure on line 62 in packages/fhir-group-management/src/components/CommodityAddEdit/Default/index.tsx GitHub Actions / test (16.17.0, ubuntu-latest)
|
||
fhirBaseUrl={fhirBaseUrl} | ||
initialValues={initialValues} | ||
cancelUrl={LIST_COMMODITY_URL} | ||
successUrl={LIST_COMMODITY_URL} | ||
postSuccess={postSuccess} | ||
validationRulesFactory={validationRulesFactory} | ||
mutationEffect={async (initialValues, values) => { | ||
const payload = generateGroupPayload(values, initialValues) | ||
return postPutGroup(fhirBaseUrl, payload) | ||
}} | ||
/> | ||
</div> | ||
</section> | ||
); | ||
}; |
18 changes: 18 additions & 0 deletions
18
...anagement/src/components/CommodityAddEdit/Default/tests/__snapshots__/index.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders correctly: active radio button 1`] = ` | ||
<input | ||
checked="" | ||
class="ant-radio-input" | ||
type="radio" | ||
value="true" | ||
/> | ||
`; | ||
|
||
exports[`renders correctly: disabled radio button 1`] = ` | ||
<input | ||
class="ant-radio-input" | ||
type="radio" | ||
value="false" | ||
/> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.