fix: mobile form ui and parse phone number bug

This commit is contained in:
Christel Westerberg
2024-07-17 09:38:30 +02:00
parent 09b1d322a7
commit da74babef9
6 changed files with 87 additions and 42 deletions

View File

@@ -27,6 +27,6 @@
@media screen and (min-width: 768px) { @media screen and (min-width: 768px) {
.container { .container {
gap: var(--Spacing-x2); gap: var(--Spacing-x3);
} }
} }

View File

@@ -1,10 +1,48 @@
.container {
display: grid;
gap: var(--Spacing-x3);
grid-template-areas:
"title"
"form"
"buttons";
}
.title {
grid-area: title;
}
.form { .form {
display: grid; display: grid;
gap: var(--Spacing-x5); gap: var(--Spacing-x5);
grid-template-columns: 1fr 1fr; grid-area: form;
} }
.btns { .btnContainer {
display: flex; display: flex;
gap: var(--Spacing-x2); flex-direction: column-reverse;
gap: var(--Spacing-x1);
grid-area: buttons;
}
.btn {
justify-content: center;
}
@media screen and (min-width: 768px) {
.container {
grid-template-areas:
"title buttons"
"form form";
}
.form {
grid-template-columns: 1fr 1fr;
}
.btnContainer {
flex-direction: row;
gap: var(--Spacing-x2);
justify-self: flex-end;
align-self: center;
}
} }

View File

@@ -61,41 +61,47 @@ export default function Form({ user }: EditFormProps) {
}) })
return ( return (
<> <section className={styles.container}>
<Header> <hgroup className={styles.title}>
<hgroup> <Title as="h4" color="red" level="h1" textTransform="capitalize">
<Title as="h4" color="red" level="h1" textTransform="capitalize"> {formatMessage({ id: "Welcome" })}
{formatMessage({ id: "Welcome" })} </Title>
</Title> <Title as="h4" color="burgundy" level="h2" textTransform="capitalize">
<Title as="h4" color="burgundy" level="h2" textTransform="capitalize"> {user.name}
{user.name} </Title>
</Title> </hgroup>
</hgroup> <div className={styles.btnContainer}>
<div className={styles.btns}> <Button
<Button asChild intent="secondary" size="small" theme="base"> asChild
<Link href={profile[lang]}> intent="secondary"
{formatMessage({ id: "Discard changes" })} size="small"
</Link> theme="base"
</Button> className={styles.btn}
<Button >
disabled={ <Link href={profile[lang]}>
!methods.formState.isValid || methods.formState.isSubmitting {formatMessage({ id: "Discard changes" })}
} </Link>
form={formId} </Button>
intent="primary" <Button
size="small" disabled={
theme="base" !methods.formState.isValid || methods.formState.isSubmitting
type="submit" }
> className={styles.btn}
{formatMessage({ id: "Save" })} form={formId}
</Button> intent="primary"
</div> size="small"
</Header> theme="base"
type="submit"
>
{formatMessage({ id: "Save" })}
</Button>
</div>
<form action={formAction} className={styles.form} id={formId}> <form action={formAction} className={styles.form} id={formId}>
<FormProvider {...methods}> <FormProvider {...methods}>
<FormContent /> <FormContent />
</FormProvider> </FormProvider>
</form> </form>
</> </section>
) )
} }

View File

@@ -61,7 +61,7 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) {
isRequired={!!registerOptions.required} isRequired={!!registerOptions.required}
name={name} name={name}
ref={field.ref} ref={field.ref}
value={parseDate(d)} value={isNaN(d) ? undefined : parseDate(d)}
> >
<Group> <Group>
<DateInput className={styles.container}> <DateInput className={styles.container}>

View File

@@ -1,7 +1,7 @@
"use client" "use client"
import "react-international-phone/style.css" import "react-international-phone/style.css"
import { parsePhoneNumber } from "libphonenumber-js" import { isValidPhoneNumber, parsePhoneNumber } from "libphonenumber-js"
import { import {
Input as AriaInput, Input as AriaInput,
Label as AriaLabel, Label as AriaLabel,
@@ -50,10 +50,11 @@ export default function Phone({
const { country, handlePhoneValueChange, inputValue, setCountry } = const { country, handlePhoneValueChange, inputValue, setCountry } =
usePhoneInput({ usePhoneInput({
defaultCountry: defaultCountry: isValidPhoneNumber(formState.defaultValues?.phoneNumber)
parsePhoneNumber( ? parsePhoneNumber(
formState.defaultValues?.phoneNumber formState.defaultValues?.phoneNumber
).country?.toLowerCase() ?? "sv", ).country?.toLowerCase()
: "sv",
disableCountryGuess: true, disableCountryGuess: true,
forceDialCode: true, forceDialCode: true,
value: phone, value: phone,

View File

@@ -1,6 +1,6 @@
import { import {
ParseError,
isPossiblePhoneNumber, isPossiblePhoneNumber,
ParseError,
parsePhoneNumber, parsePhoneNumber,
validatePhoneNumberLength, validatePhoneNumberLength,
} from "libphonenumber-js" } from "libphonenumber-js"