feat: pre-fill first/last name on setup page from user's registered name
This commit is contained in:
@@ -17,10 +17,18 @@
|
||||
import type { PageProps } from './$types';
|
||||
|
||||
let { data }: PageProps = $props();
|
||||
$inspect(data);
|
||||
|
||||
const userFullName = data.user?.name;
|
||||
let firstName = $state(splitName(userFullName).first);
|
||||
let lastName = $state(splitName(userFullName).last);
|
||||
let phoneNumber = $state('');
|
||||
|
||||
function splitName(fullName: string | null | undefined): { first: string; last: string } {
|
||||
if (!fullName) return { first: '', last: '' };
|
||||
const parts = fullName.trim().split(/\s+/);
|
||||
return { first: parts[0] ?? '', last: parts.slice(1).join(' ') };
|
||||
}
|
||||
|
||||
function handlePhoneInput(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
phoneNumber = clientFormatPhoneNumber(input.value);
|
||||
@@ -38,8 +46,8 @@
|
||||
<p class="mx-auto text-center my-4">{data.user?.email}</p>
|
||||
<div class="flex flex-col">
|
||||
<input type="text" name="userId" value={data.user?.id} class="hidden"/>
|
||||
<input type="text" name="firstName" placeholder="First Name" class="my-2" />
|
||||
<input type="text" name="lastName" placeholder="Last Name" class="my-2" />
|
||||
<input type="text" name="firstName" placeholder="First Name" class="my-2" bind:value={firstName} />
|
||||
<input type="text" name="lastName" placeholder="Last Name" class="my-2" bind:value={lastName} />
|
||||
<input
|
||||
type="tel"
|
||||
name="phoneNumber"
|
||||
|
||||
Reference in New Issue
Block a user