-
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.
- Loading branch information
1 parent
9abac89
commit 7db485c
Showing
10 changed files
with
90 additions
and
94 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
30 changes: 23 additions & 7 deletions
30
apps/admin/src/components/common/DeliveryOptionsPackageType.vue
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,23 +1,39 @@ | ||
<template> | ||
<span | ||
v-if="deliveryOptions.packageType" | ||
v-test="[$.type.__name, deliveryOptions.packageType]"> | ||
<PdkIcon :icon="deliveryOptions.packageType" /> | ||
v-if="resolved.deliveryOptions?.packageType" | ||
v-test="[$.type.__name, resolved.deliveryOptions.packageType]"> | ||
<PdkIcon :icon="resolved.deliveryOptions.packageType" /> | ||
|
||
<span | ||
:title="translate(getPackageTypeTranslation())" | ||
v-text="translate(getPackageTypeTranslation(deliveryOptions.packageType))" /> | ||
v-text="translate(getPackageTypeTranslation(resolved.deliveryOptions.packageType))" /> | ||
|
||
<DigitalStampWeightRange | ||
v-if="resolved.deliveryOptions?.packageType === PackageTypeName.DigitalStamp" | ||
:weight="weight" /> | ||
</span> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import {computed} from 'vue'; | ||
import {get, type MaybeRef} from '@vueuse/core'; | ||
import {type Shipment} from '@myparcel-pdk/common'; | ||
import {type Plugin} from '@myparcel-pdk/admin'; | ||
import {isOfType} from '@myparcel/ts-utils'; | ||
import {PackageTypeName} from '@myparcel/constants'; | ||
import {getPackageTypeTranslation} from '../../utils'; | ||
import {useLanguage} from '../../composables'; | ||
import DigitalStampWeightRange from './DigitalStampWeightRange.vue'; | ||
defineProps<{ | ||
deliveryOptions: Shipment.ModelDeliveryOptions; | ||
}>(); | ||
const props = defineProps<{shipmentOrOrder: MaybeRef<Shipment.ModelShipment | Plugin.ModelPdkOrder>}>(); | ||
const {translate} = useLanguage(); | ||
const resolved = computed(() => get(props.shipmentOrOrder)); | ||
const weight = computed(() => { | ||
return isOfType<Shipment.ModelPhysicalProperties>(resolved.value.physicalProperties, 'weight') | ||
? resolved.value.physicalProperties.weight | ||
: resolved.value.physicalProperties?.totalWeight ?? 0; | ||
}); | ||
</script> |
20 changes: 7 additions & 13 deletions
20
apps/admin/src/components/common/DigitalStampWeightRange.vue
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,20 +1,14 @@ | ||
<template> | ||
<span | ||
v-if="weightRange" | ||
v-test="[$.type.__name, weightRange]"> | ||
|
||
<span | ||
:title="translate('digital_stamp_weight_range', {weightRange})" | ||
v-text="`${weightRange.min}g - ${weightRange.max}g`" /> | ||
</span> | ||
<span v-text="defaultRange" /> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import {useLanguage} from '../../composables'; | ||
import {toRefs} from 'vue'; | ||
import {useDigitalStampRanges} from '../../composables'; | ||
const props = defineProps<{weight: number}>(); | ||
defineProps<{ | ||
weightRange: {min: number; max: number; average: number}; | ||
}>(); | ||
const propRefs = toRefs(props); | ||
const {translate} = useLanguage(); | ||
const {defaultRange} = useDigitalStampRanges(propRefs.weight); | ||
</script> |
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,38 @@ | ||
import {computed, type ComputedRef} from 'vue'; | ||
import {get, type MaybeRef} from '@vueuse/core'; | ||
import {type Plugin} from '@myparcel-pdk/common'; | ||
import {type SelectOptionWithPlainLabel} from '../types'; | ||
import {useOrderData} from './orders'; | ||
|
||
interface UseDigitalStampRanges { | ||
ranges: ComputedRef<SelectOptionWithPlainLabel<number, string>[]>; | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments | ||
currentRange: ComputedRef<SelectOptionWithPlainLabel<number, string>>; | ||
} | ||
|
||
export const useDigitalStampRanges = (weight: MaybeRef<number>): UseDigitalStampRanges => { | ||
// todo: move this to global context | ||
const {order} = useOrderData(); | ||
|
||
const allRanges = computed<Plugin.DigitalStampRange[]>(() => get(order).digitalStampRanges ?? []); | ||
|
||
const ranges = computed<SelectOptionWithPlainLabel<number, string>[]>(() => { | ||
return allRanges.value.map((range) => ({ | ||
plainLabel: `${range.min}g – ${range.max}g`, | ||
value: range.average, | ||
})); | ||
}); | ||
|
||
const currentRange = computed(() => { | ||
const resolvedWeight = get(weight); | ||
|
||
const matchingRange = allRanges.value.find((range) => range.min <= resolvedWeight && range.max >= resolvedWeight); | ||
|
||
return ranges.value.find((range) => range.value === matchingRange?.average) ?? ranges.value[0]; | ||
}); | ||
|
||
return { | ||
ranges, | ||
currentRange, | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
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