owltide/plugins/schedule-payload-type.ts
Hornwitser 73bb12c104
All checks were successful
/ build (push) Successful in 1m29s
/ deploy (push) Successful in 16s
Add payload plugin for ClientSchedule
Add plugin to serialise ClientSchedule objects as JSON when it's passed
from the server to client on SSR requests.
2025-06-13 22:01:42 +02:00

25 lines
577 B
TypeScript

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 })
},
);
});