Skip to content

Commit

Permalink
fix: select standard delivery initially
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Apr 15, 2024
1 parent 559a830 commit 652dcfd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</div>
</template>

<script generic="T extends string | null" lang="ts" setup>
<script lang="ts" setup>
import {toRefs, watch, toValue} from 'vue';
import {useVModel} from '@vueuse/core';
import {
Expand All @@ -33,21 +33,25 @@ import {
RadioInput,
type WithElement,
} from '@myparcel-do/shared';
import {DeliveryTypeName} from '@myparcel/constants';
import {parseJson} from '../../../../utils';
import {type SelectedDeliveryMoment} from '../../../../types';
import {FIELD_DELIVERY_MOMENT} from '../../../../data';
import {useOptionsGroupedByCarrier, useLanguage, useSelectedValues} from '../../../../composables';
import {GroupInput} from '../../../../components';
// eslint-disable-next-line vue/no-unused-properties
const props = defineProps<WithElement<RadioGroupProps<T>>>();
const emit = defineEmits<RadioGroupEmits<T>>();
const props = defineProps<WithElement<RadioGroupProps>>();
const emit = defineEmits<RadioGroupEmits>();
const propRefs = toRefs(props);
const model = useVModel(props, undefined, emit);
const {deliveryDate} = useSelectedValues();
const {translate} = useLanguage();
const {options, grouped} = useOptionsGroupedByCarrier(propRefs.element);
// @ts-expect-error todo: fix types
const {options, grouped} = useOptionsGroupedByCarrier<string>(propRefs.element);
watch(
[options, deliveryDate],
Expand All @@ -56,8 +60,13 @@ watch(
return;
}
const [first] = toValue(options);
model.value = first.value;
const resolvedOptions = toValue(options);
const firstStandardDelivery = resolvedOptions.find((option) => {
return parseJson<SelectedDeliveryMoment>(option.value).deliveryType === DeliveryTypeName.Standard;
});
model.value = firstStandardDelivery?.value ?? resolvedOptions[0]?.value;
},
{immediate: options.value.length > 0, deep: true},
);
Expand Down
4 changes: 2 additions & 2 deletions libs/shared/src/types/input.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export type RadioEmits<T extends RadioModelValue> = ElementEmits<T>;

export type RadioGroupModelValue = string;

export type RadioGroupProps<T extends RadioGroupModelValue> = InputProps<T> & OptionsProps<T>;
export type RadioGroupProps<T extends RadioGroupModelValue = RadioGroupModelValue> = InputProps<T> & OptionsProps<T>;

export type RadioGroupEmits<T extends RadioGroupModelValue> = ElementEmits<T>;
export type RadioGroupEmits<T extends RadioGroupModelValue = RadioGroupModelValue> = ElementEmits<T>;

export type TextInputModelValue = string | number | undefined;

Expand Down

0 comments on commit 652dcfd

Please sign in to comment.