-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add org unit edit form * feat: small changes to org unit select and image select * fix(orgunit): fix image preview url * fix(orgunit): create default valueFormatter * fix: fix type issue * feat: minor fixes --------- Co-authored-by: Birk Johansson <[email protected]>
- Loading branch information
Showing
13 changed files
with
284 additions
and
91 deletions.
There are no files selected for viewing
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
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
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
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
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
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,80 @@ | ||
import React from 'react' | ||
import { useQuery } from 'react-query' | ||
import { useParams } from 'react-router-dom' | ||
import { DefaultEditFormContents, FormBase } from '../../components' | ||
import { | ||
ATTRIBUTE_VALUES_FIELD_FILTERS, | ||
DEFAULT_FIELD_FILTERS, | ||
SECTIONS_MAP, | ||
useOnSubmitEdit, | ||
validate, | ||
} from '../../lib' | ||
import { useBoundResourceQueryFn } from '../../lib/query/useBoundQueryFn' | ||
import { OrganisationUnit, PickWithFieldFilters } from '../../types/generated' | ||
import { OrganisationUnitFormField, organisationUnitSchema } from './form' | ||
|
||
const fieldFilters = [ | ||
...DEFAULT_FIELD_FILTERS, | ||
...ATTRIBUTE_VALUES_FIELD_FILTERS, | ||
'name', | ||
'code', | ||
'shortName', | ||
'openingDate', | ||
'closedDate', | ||
'comment', | ||
'image[id,name]', | ||
'description', | ||
'contactPerson', | ||
'address', | ||
'email', | ||
'phoneNumber', | ||
'url', | ||
'geometry', | ||
'dataSets', | ||
'programs', | ||
'level', | ||
'path', | ||
'parent[id,path, displayName]', | ||
] as const | ||
|
||
export type OrgUnitFormValues = PickWithFieldFilters< | ||
OrganisationUnit, | ||
typeof fieldFilters | ||
> | ||
|
||
const section = SECTIONS_MAP.organisationUnit | ||
|
||
export const Component = () => { | ||
const queryFn = useBoundResourceQueryFn() | ||
const modelId = useParams().id as string | ||
|
||
const query = { | ||
resource: 'organisationUnits', | ||
id: modelId, | ||
params: { | ||
fields: fieldFilters.concat(), | ||
}, | ||
} | ||
const orgUnit = useQuery({ | ||
queryKey: [query], | ||
queryFn: queryFn<OrgUnitFormValues>, | ||
}) | ||
|
||
return ( | ||
<FormBase | ||
onSubmit={useOnSubmitEdit({ | ||
section, | ||
modelId, | ||
})} | ||
section={section} | ||
initialValues={orgUnit.data} | ||
validate={(values: OrgUnitFormValues) => { | ||
return validate(organisationUnitSchema, values) | ||
}} | ||
> | ||
<DefaultEditFormContents section={section}> | ||
<OrganisationUnitFormField /> | ||
</DefaultEditFormContents> | ||
</FormBase> | ||
) | ||
} |
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.