mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-03-30 03:06:37 +00:00
feat: add user display name field (#898)
Co-authored-by: Elias Schneider <login@eliasschneider.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import { preventDefault } from '$lib/utils/event-util';
|
||||
import { createForm } from '$lib/utils/form-util';
|
||||
import { tryCatch } from '$lib/utils/try-catch-util';
|
||||
import { emptyToUndefined } from '$lib/utils/zod-util';
|
||||
import { z } from 'zod/v4';
|
||||
|
||||
let {
|
||||
@@ -24,7 +25,7 @@
|
||||
|
||||
const formSchema = z.object({
|
||||
firstName: z.string().min(1).max(50),
|
||||
lastName: z.string().max(50).optional(),
|
||||
lastName: emptyToUndefined(z.string().max(50).optional()),
|
||||
username: z
|
||||
.string()
|
||||
.min(2)
|
||||
|
||||
@@ -41,6 +41,7 @@ export type AllAppConfig = AppConfig & {
|
||||
ldapAttributeUserEmail: string;
|
||||
ldapAttributeUserFirstName: string;
|
||||
ldapAttributeUserLastName: string;
|
||||
ldapAttributeUserDisplayName: string;
|
||||
ldapAttributeUserProfilePicture: string;
|
||||
ldapAttributeGroupMember: string;
|
||||
ldapAttributeGroupUniqueIdentifier: string;
|
||||
|
||||
@@ -8,6 +8,7 @@ export type User = {
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName?: string;
|
||||
displayName: string;
|
||||
isAdmin: boolean;
|
||||
userGroups: UserGroup[];
|
||||
customClaims: CustomClaim[];
|
||||
@@ -18,6 +19,6 @@ export type User = {
|
||||
|
||||
export type UserCreate = Omit<User, 'id' | 'customClaims' | 'ldapId' | 'userGroups'>;
|
||||
|
||||
export type UserSignUp = Omit<UserCreate, 'isAdmin' | 'disabled'> & {
|
||||
export type UserSignUp = Omit<UserCreate, 'isAdmin' | 'disabled' | 'displayName'> & {
|
||||
token?: string;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
import { setLocale as setParaglideLocale, type Locale } from '$lib/paraglide/runtime';
|
||||
import {
|
||||
extractLocaleFromCookie,
|
||||
setLocale as setParaglideLocale,
|
||||
type Locale
|
||||
} from '$lib/paraglide/runtime';
|
||||
import { setDefaultOptions } from 'date-fns';
|
||||
import { z } from 'zod/v4';
|
||||
|
||||
export async function setLocale(locale: Locale, reload = true) {
|
||||
await setLocaleForLibraries(locale);
|
||||
setParaglideLocale(locale, { reload });
|
||||
}
|
||||
|
||||
export async function setLocaleForLibraries(
|
||||
locale: Locale = (extractLocaleFromCookie() as Locale) || 'en'
|
||||
) {
|
||||
const [zodResult, dateFnsResult] = await Promise.allSettled([
|
||||
import(`../../../node_modules/zod/v4/locales/${locale}.js`),
|
||||
import(`../../../node_modules/date-fns/locale/${locale}.js`)
|
||||
@@ -14,8 +25,6 @@ export async function setLocale(locale: Locale, reload = true) {
|
||||
console.warn(`Failed to load zod locale for ${locale}:`, zodResult.reason);
|
||||
}
|
||||
|
||||
setParaglideLocale(locale, { reload });
|
||||
|
||||
if (dateFnsResult.status === 'fulfilled') {
|
||||
setDefaultOptions({
|
||||
locale: dateFnsResult.value.default
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { m } from '$lib/paraglide/messages';
|
||||
import z from 'zod/v4';
|
||||
import { z } from 'zod/v4';
|
||||
|
||||
export const emptyToUndefined = <T>(validation: z.ZodType<T>) =>
|
||||
z.preprocess((v) => (v === '' ? undefined : v), validation);
|
||||
z.preprocess((v) => (v === '' ? undefined : v), validation.optional());
|
||||
|
||||
export const optionalUrl = z
|
||||
.url()
|
||||
|
||||
Reference in New Issue
Block a user