Skip to content

Commit

Permalink
fix(admin)!: fix drop off inputs not inheriting from parent element
Browse files Browse the repository at this point in the history
BREAKING CHANGE: input of useDropOffInputContext has changed
  • Loading branch information
EdieLemoine committed Mar 13, 2024
1 parent 68d1500 commit 3b1bea7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@
</template>

<script lang="ts" setup>
import {toRefs} from 'vue';
import {
AdminComponent,
type DropOffInputEmits,
type DropOffInputProps,
useDropOffInputContext,
} from '@myparcel-pdk/admin';
// eslint-disable-next-line vue/no-unused-properties
const props = defineProps<DropOffInputProps>();
const emit = defineEmits<DropOffInputEmits>();
const propRefs = toRefs(props);
const {weekdaysObject, cutoffElements, toggleElements, toggleRefs, cutoffRefs} = useDropOffInputContext(
propRefs.modelValue?.value,
emit,
);
const {weekdaysObject, cutoffElements, toggleElements, toggleRefs, cutoffRefs} = useDropOffInputContext(props, emit);
</script>
11 changes: 8 additions & 3 deletions apps/admin/src/composables/useDropOffInputContext.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {reactive, watch} from 'vue';
import {type Settings, type Shipment} from '@myparcel-pdk/common';
import {createFormElement, createObjectWithKeys} from '../utils';
import {type DropOffInputProps} from '../types';
import {useWeekdays, type Weekday, type Weekdays} from './useWeekdays';

type UseDropOffInputContext = (
possibilities?: Settings.ModelDropOffPossibilities,
props: DropOffInputProps,
emit?: (name: 'update:modelValue', ...args: unknown[]) => void,
) => {
weekdaysObject: Record<Weekday, string>;
Expand All @@ -16,7 +17,8 @@ type UseDropOffInputContext = (
};

// eslint-disable-next-line max-lines-per-function
export const useDropOffInputContext: UseDropOffInputContext = (possibilities, emit) => {
// @ts-expect-error todo
export const useDropOffInputContext: UseDropOffInputContext = (props, emit) => {
const {weekdaysObject, weekdays} = useWeekdays();

const createReactiveObject = <K extends keyof Required<Shipment.ModelDropOffDay>>(
Expand All @@ -25,17 +27,20 @@ export const useDropOffInputContext: UseDropOffInputContext = (possibilities, em
) => {
return reactive(
createObjectWithKeys(weekdays, (day) => {
return possibilities?.dropOffDays.find(({weekday}) => weekday === day)?.[property] ?? defaultValue;
return props.modelValue?.dropOffDays.find(({weekday}) => weekday === day)?.[property] ?? defaultValue;
}),
);
};

const toggleRefs = createReactiveObject('dispatch', false);
const cutoffRefs = createReactiveObject('cutoffTime', '16:00');

const {component: _, ...restElement} = props.element;

const createElements = (reactiveObject: Record<Weekday, unknown>, name: string) =>
createObjectWithKeys(weekdays, (day) =>
createFormElement({
...restElement,
// @ts-expect-error Not worth the effort
ref: reactiveObject[day],
name: `${name}${day.toString()}`,
Expand Down

0 comments on commit 3b1bea7

Please sign in to comment.