owltide/plugins/schedule-payload-type.ts

26 lines
577 B
TypeScript
Raw Normal View History

import { Info } from "~/shared/utils/luxon";
export default definePayloadPlugin(() => {
definePayloadReducer(
"ClientSchedule",
data => {
if (!(data instanceof ClientSchedule)) {
return;
}
const accountStore = useAccountStore();
return {
timezone: accountStore.activeTimezone,
locale: accountStore.activeLocale,
api: data.toApi(false)
};
},
);
definePayloadReviver(
"ClientSchedule",
({ timezone, locale, api }) => {
const zone = Info.normalizeZone(timezone);
return ClientSchedule.fromApi(api, { zone, locale })
},
);
});