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.
This commit is contained in:
parent
fb7a60db28
commit
73bb12c104
3 changed files with 28 additions and 2 deletions
25
plugins/schedule-payload-type.ts
Normal file
25
plugins/schedule-payload-type.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
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 })
|
||||
},
|
||||
);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue