-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(order): add helpful text when using postnl age check
- Loading branch information
1 parent
36b9fbf
commit f9a5fdd
Showing
13 changed files
with
66 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const createLabel = <Label extends string | undefined>(label: Label, type: string): Label => { | ||
return (label ? `${label}_${type}` : undefined) as Label; | ||
}; |
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,6 @@ | ||
import {snakeCase} from 'lodash-unified'; | ||
import {type Shipment} from '@myparcel-pdk/common'; | ||
import {SHIPMENT_OPTIONS} from '../shipmentOptions'; | ||
|
||
export const getFieldLabel = (name: keyof Shipment.ModelShipmentOptions): string => | ||
snakeCase(`${SHIPMENT_OPTIONS}_${name}`); | ||
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,11 @@ | ||
import {type FormInstance} from '@myparcel/vue-form-builder'; | ||
import {CarrierName} from '@myparcel/constants'; | ||
import {FIELD_AGE_CHECK} from '../shipmentOptions'; | ||
import {triStateFieldIsEnabled} from './triStateFieldIsEnabled'; | ||
import {getFormCarrierName} from './getFormCarrierName'; | ||
|
||
export const hasPostNlAgeCheck = (form: FormInstance): boolean => { | ||
const carrier = getFormCarrierName(form); | ||
|
||
return CarrierName.PostNl === carrier && triStateFieldIsEnabled(form, FIELD_AGE_CHECK); | ||
}; | ||
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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
export * from './addBulkEditNotification'; | ||
export * from './createDefaultOption'; | ||
export * from './createHasShipmentOptionWatcher'; | ||
export * from './createLabel'; | ||
export * from './defineFormField'; | ||
export * from './getCarrier'; | ||
export * from './getFieldLabel'; | ||
export * from './getFormCarrierName'; | ||
export * from './getInsuranceOptions'; | ||
export * from './getPackageTypes'; | ||
export * from './hasPostNlAgeCheck'; | ||
export * from './hasShipmentOption'; | ||
export * from './isPackageTypePackage'; | ||
export * from './resolveFormComponent'; | ||
export * from './setFieldProp'; | ||
export * from './setPostNlAgeCheckSubtext'; | ||
export * from './triStateFieldIsEnabled'; | ||
export * from './updateFieldsDefaults'; |
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,17 @@ | ||
import {type InteractiveElementInstance} from '@myparcel/vue-form-builder'; | ||
import {CarrierName} from '@myparcel/constants'; | ||
import {AGE_CHECK, FIELD_AGE_CHECK, KEY_SUBTEXT} from '../shipmentOptions'; | ||
import {setFieldProp} from './setFieldProp'; | ||
import {hasPostNlAgeCheck} from './hasPostNlAgeCheck'; | ||
import {getFieldLabel} from './getFieldLabel'; | ||
import {createLabel} from './createLabel'; | ||
|
||
export const setPostNlAgeCheckSubtext = ({form}: InteractiveElementInstance): void => { | ||
const defaultKey = createLabel(getFieldLabel(AGE_CHECK), KEY_SUBTEXT); | ||
|
||
if (hasPostNlAgeCheck(form)) { | ||
setFieldProp(form, FIELD_AGE_CHECK, KEY_SUBTEXT, `${defaultKey}_${CarrierName.PostNl}`); | ||
} else { | ||
setFieldProp(form, FIELD_AGE_CHECK, KEY_SUBTEXT, defaultKey); | ||
} | ||
}; | ||
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
11 changes: 3 additions & 8 deletions
11
apps/admin/src/forms/shipmentOptions/fields/createSignatureField.ts
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 |
---|---|---|
@@ -1,16 +1,11 @@ | ||
import {type InteractiveElementConfiguration} from '@myparcel/vue-form-builder'; | ||
import {CarrierName} from '@myparcel/constants'; | ||
import {type ShipmentOptionsRefs} from '../types'; | ||
import {FIELD_AGE_CHECK, FIELD_SIGNATURE} from '../field'; | ||
import {getFormCarrierName, triStateFieldIsEnabled} from '../../helpers'; | ||
import {FIELD_SIGNATURE} from '../field'; | ||
import {hasPostNlAgeCheck} from '../../helpers'; | ||
import {createShipmentOptionField} from './createShipmentOptionField'; | ||
|
||
export const createSignatureField = (refs: ShipmentOptionsRefs): InteractiveElementConfiguration => { | ||
return createShipmentOptionField(refs, FIELD_SIGNATURE, { | ||
readOnlyWhen({form}) { | ||
const carrier = getFormCarrierName(form); | ||
|
||
return CarrierName.PostNl === carrier && triStateFieldIsEnabled(form, FIELD_AGE_CHECK); | ||
}, | ||
readOnlyWhen: ({form}) => hasPostNlAgeCheck(form), | ||
}); | ||
}; |