Skip to content

Commit

Permalink
add default field region to location
Browse files Browse the repository at this point in the history
  • Loading branch information
rdonigian committed Jan 24, 2025
1 parent b1a0a0d commit bd1db2b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fragment FieldRegionLookupItem on FieldRegion {
id
name {
value
}
}
1 change: 1 addition & 0 deletions src/components/form/Lookup/FieldRegion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { FieldRegionLookupItemFragment as FieldRegionLookupItem } from './FieldRegionField.graphql';
7 changes: 7 additions & 0 deletions src/scenes/Locations/Detail/LocationDetail.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ fragment LocationDetail on Location {
...FundingAccountCard
}
}
defaultFieldRegion {
canRead
canEdit
value {
...DisplayFieldRegion
}
}
mapImage {
canRead
canEdit
Expand Down
9 changes: 8 additions & 1 deletion src/scenes/Locations/Edit/EditLocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,28 @@ export const EditLocation = (props: EditLocationProps) => {
type: location.type.value,
isoAlpha3: location.isoAlpha3.value,
fundingAccountId: location.fundingAccount.value,
defaultFieldRegionId: location.defaultFieldRegion.value,
},
}
: undefined,
[location]
);

const onSubmit: FormProps['onSubmit'] = async ({
location: { fundingAccountId, mapImage: mapImages, ...rest },
location: {
fundingAccountId,
defaultFieldRegionId,
mapImage: mapImages,
...rest
},
}) => {
const [uploadedImageInfo, finalizeUpload] = await uploadFile(
mapImages?.[0]
);

const input: UpdateLocation = {
...rest,
defaultFieldRegionId: defaultFieldRegionId?.id ?? null,
fundingAccountId: fundingAccountId?.id ?? null,
mapImage: uploadedImageInfo,
};
Expand Down
14 changes: 14 additions & 0 deletions src/scenes/Locations/LocationForm/LocationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
UpdateLocation,
} from '~/api/schema.graphql';
import { labelFrom } from '~/common';
import { FieldRegionField } from '~/components/form/Lookup';
import { FieldRegionLookupItem } from '~/components/form/Lookup/FieldRegion';
import {
DialogForm,
DialogFormProps,
Expand All @@ -31,6 +33,7 @@ export interface LocationFormValues<
location: Merge<
CreateOrUpdateType,
{
defaultFieldRegionId?: FieldRegionLookupItem | null;
fundingAccountId?: FundingAccountLookupItem | null;
mapImage?: File[];
}
Expand Down Expand Up @@ -103,6 +106,17 @@ export const LocationForm = <CreateOrUpdateInput, R extends any>({
{(props) => <FundingAccountField margin="none" {...props} />}
</SecuredField>
</Grid>
<Grid item xs={12}>
<SecuredField obj={location} name="defaultFieldRegionId">
{(props) => (
<FieldRegionField
margin="none"
label="Default Field Region"
{...props}
/>
)}
</SecuredField>
</Grid>
<Grid item xs={12}>
<DropzoneField
name="mapImage"
Expand Down

0 comments on commit bd1db2b

Please sign in to comment.