Skip to content

Commit

Permalink
fix: trim first and last names
Browse files Browse the repository at this point in the history
  • Loading branch information
darkoatanasovski committed Dec 7, 2022
1 parent 867ac63 commit cfb5b0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/services/inplayer.account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ export const getFreshJwtToken = async ({ auth }: { auth: AuthData }) => auth;

export const updateCustomer: UpdateCustomer = async (values) => {
try {
const fullName = `${values.firstName} ${values.lastName}`;
const firstName = values.firstName?.trim() || '';
const lastName = values.lastName?.trim() || '';
const fullName = `${firstName} ${lastName}`;

const response = await InPlayer.Account.updateAccount({
fullName,
metadata: {
...(values?.consents && { consents: JSON.stringify(values.consents) }),
first_name: values.firstName?.replace(/\s\s+/g, ' ')?.trim() || '',
surname: values.lastName?.replace(/\s\s+/g, ' ')?.trim() || '',
first_name: firstName,
surname: lastName,
},
});

Expand All @@ -84,7 +87,7 @@ function processAccount(account: AccountData): Customer {
let lastName = metadata?.surname as string;
if (!firstName && !lastName) {
const nameParts = fullName.split(' ');
firstName = nameParts[0]?.trim() || '';
firstName = nameParts[0] || '';
lastName = nameParts.slice(1)?.join(' ');
}
return {
Expand Down
6 changes: 1 addition & 5 deletions src/stores/AccountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ export async function updateUser(values: { firstName: string; lastName: string }
await withAccountService(async ({ accountService, sandbox }) => {
useAccountStore.setState({ loading: true });

const { auth, user, canUpdateEmail } = useAccountStore.getState();

if (values.email && !canUpdateEmail) {
throw new Error('Email update not supported');
}
const { auth, user } = useAccountStore.getState();

if (!auth || !user) throw new Error('no auth');

Expand Down

0 comments on commit cfb5b0b

Please sign in to comment.