mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
fixes
This commit is contained in:
@@ -49,7 +49,7 @@ import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { notify, PageHeader, useErrorHandler, passwordSchema as strongPasswordSchema, PasswordRequirements, getCountryCode, splitPersonName, joinPersonName } from '@ema-platform/ui';
|
||||
import { notify, PageHeader, useErrorHandler, passwordSchema as strongPasswordSchema, PasswordRequirements, getCountryCode } from '@ema-platform/ui';
|
||||
import { useApiMutation, useLocalized } from '@ema-platform/api';
|
||||
import { PORTAL_PERMISSIONS, setUser, useCurrentProfile, usePermissions } from '@ema-platform/auth';
|
||||
import { SUPPORTED_LANGUAGES, type AppLanguage } from '../../../i18n/config';
|
||||
@@ -89,6 +89,15 @@ function getInitials(name: string, fallback: string) {
|
||||
return letters.toUpperCase();
|
||||
}
|
||||
|
||||
function splitProfileName(fullName: string) {
|
||||
const [firstName = '', middleName = '', ...lastName] = fullName.trim().split(/\s+/);
|
||||
return { firstName, middleName, lastName: lastName.join(' ') };
|
||||
}
|
||||
|
||||
function formatProfileName({ firstName, middleName, lastName }: Pick<ProfileValues, 'firstName' | 'middleName' | 'lastName'>) {
|
||||
return [firstName, middleName, lastName].filter(Boolean).join(' ');
|
||||
}
|
||||
|
||||
function normalizeName(name: string) {
|
||||
return name.trim().replace(/\s+/g, ' ');
|
||||
}
|
||||
@@ -196,7 +205,7 @@ export function ProfilePage() {
|
||||
// already holds so the form does not flash empty on a refetch.
|
||||
const currentProfile = resolvedProfile ?? storedProfile;
|
||||
if (currentProfile) {
|
||||
const accountName = user?.name?.en ? splitPersonName(user.name.en) : null;
|
||||
const accountName = user?.name?.en ? splitProfileName(user.name.en) : null;
|
||||
setLoadedProfile({
|
||||
professionId: currentProfile.professionId || currentProfile.profession?.id || '',
|
||||
firstName: accountName?.firstName || currentProfile.firstName || '',
|
||||
@@ -277,7 +286,7 @@ export function ProfilePage() {
|
||||
|
||||
setIsSavingProfile(true);
|
||||
try {
|
||||
const profileName = splitPersonName(values.nameEn);
|
||||
const profileName = splitProfileName(values.nameEn);
|
||||
const saves: Promise<unknown>[] = [
|
||||
updateTrigger({
|
||||
url: '/auth/update-profile',
|
||||
@@ -354,7 +363,7 @@ export function ProfilePage() {
|
||||
const onSaveProfile = async (values: ProfileValues) => {
|
||||
if (!profileId) return;
|
||||
|
||||
const fullName = joinPersonName(values);
|
||||
const fullName = formatProfileName(values);
|
||||
if (user && normalizeName(fullName) !== normalizeName(user.name.en)) {
|
||||
notify.error(t('profile.nameMismatch'));
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user