review(front): refacto url-manager (#8861)

Replace https://github.com/twentyhq/twenty/pull/8855
This commit is contained in:
Antoine Moreaux
2024-12-05 11:47:51 +01:00
committed by GitHub
parent 7ab00a4c82
commit 081ecbcfaf
33 changed files with 639 additions and 271 deletions

View File

@ -1,5 +1,6 @@
import { AtomEffect } from 'recoil';
import omit from 'lodash.omit';
import { z } from 'zod';
import { cookieStorage } from '~/utils/cookie-storage';
@ -20,6 +21,20 @@ export const localStorageEffect =
});
};
const customCookieAttributeZodSchema = z.object({
cookieAttributes: z.object({
expires: z.union([z.number(), z.instanceof(Date)]).optional(),
path: z.string().optional(),
domain: z.string().optional(),
secure: z.boolean().optional(),
}),
});
export const isCustomCookiesAttributesValue = (
value: unknown,
): value is { cookieAttributes: Cookies.CookieAttributes } =>
customCookieAttributeZodSchema.safeParse(value).success;
export const cookieStorageEffect =
<T>(
key: string,
@ -52,9 +67,7 @@ export const cookieStorageEffect =
const cookieAttributes = {
...defaultAttributes,
...(typeof newValue === 'object' &&
'cookieAttributes' in newValue &&
typeof newValue.cookieAttributes === 'object'
...(isCustomCookiesAttributesValue(newValue)
? newValue.cookieAttributes
: {}),
};