-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
474 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { required, useForm } from '@modular-forms/preact' | ||
import { useSignalEffect } from '@preact/signals' | ||
|
||
import { Porting } from '../types' | ||
|
||
type Props = { | ||
porting: Porting | ||
onValidationChange?: (event: { isValid: boolean }) => unknown | ||
onSubmit: (data: PortingForm) => unknown | ||
} | ||
|
||
type PortingForm = { | ||
accountPin: string | ||
accountNumber: string | ||
birthday: string | ||
firstName: string | ||
lastName: string | ||
} | ||
|
||
export function PortingForm({ porting, onValidationChange, onSubmit }: Props) { | ||
const [portingForm, { Form, Field }] = useForm<PortingForm>({ | ||
initialValues: { | ||
accountNumber: porting.accountNumber || '', | ||
accountPin: porting.accountPinExists ? '[***]' : '', | ||
birthday: porting.birthday || '', | ||
firstName: porting.firstName || '', | ||
lastName: porting.lastName || '', | ||
}, | ||
validateOn: 'blur', | ||
}) | ||
|
||
useSignalEffect(() => { | ||
const isValid = !portingForm.invalid.value | ||
onValidationChange?.({ isValid }) | ||
}) | ||
|
||
return ( | ||
<Form id="gigsPortingEmbedForm" role="form" onSubmit={onSubmit}> | ||
<Field name="accountNumber" validate={[required('Please enter')]}> | ||
{(field, props) => ( | ||
<div> | ||
<label for="accountNumber">Account Number</label> | ||
<input | ||
id="accountNumber" | ||
type="text" | ||
value={field.value} | ||
{...props} | ||
/> | ||
{field.error && <div>{field.error}</div>} | ||
</div> | ||
)} | ||
</Field> | ||
|
||
<Field name="accountPin" validate={[required('Please enter')]}> | ||
{(field, props) => ( | ||
<div> | ||
<label for="accountPin">Account PIN</label> | ||
<input id="accountPin" type="text" value={field.value} {...props} /> | ||
{field.error && <div>{field.error}</div>} | ||
</div> | ||
)} | ||
</Field> | ||
|
||
<Field name="birthday" validate={[required('Please enter')]}> | ||
{(field, props) => ( | ||
<div> | ||
<label for="birthday">Birthday</label> | ||
<input id="birthday" type="text" value={field.value} {...props} /> | ||
{field.error && <div>{field.error}</div>} | ||
</div> | ||
)} | ||
</Field> | ||
|
||
<Field name="firstName" validate={[required('Please enter')]}> | ||
{(field, props) => ( | ||
<div> | ||
<label for="firstName">First Name</label> | ||
<input id="firstName" type="text" value={field.value} {...props} /> | ||
{field.error && <div>{field.error}</div>} | ||
</div> | ||
)} | ||
</Field> | ||
|
||
<Field name="lastName" validate={[required('Please enter')]}> | ||
{(field, props) => ( | ||
<div> | ||
<label for="lastName">Last Name</label> | ||
<input id="lastName" type="text" value={field.value} {...props} /> | ||
{field.error && <div>{field.error}</div>} | ||
</div> | ||
)} | ||
</Field> | ||
</Form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import { Meta } from '@storybook/preact' | ||
|
||
import { portingFactory } from '@/testing/factories/porting' | ||
|
||
import { PortingEmbed } from '../PortingEmbed' | ||
|
||
export default { | ||
title: 'Porting Embed/Base', | ||
const meta: Meta<typeof PortingEmbed> = { | ||
title: 'Porting/Embed', | ||
component: PortingEmbed, | ||
tags: ['autodocs'], | ||
argTypes: { | ||
token: { control: 'text' }, | ||
initialPorting: { control: 'object' }, | ||
onPortingUpdate: { action: 'onPortingUpdate' }, | ||
onValidationChange: { action: 'onValidationChange' }, | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<div> | ||
{Story()} | ||
<button form="gigsPortingEmbedForm" type="submit"> | ||
Submit! | ||
</button> | ||
</div> | ||
), | ||
], | ||
} | ||
|
||
export default meta | ||
|
||
export const EmptyPorting = { | ||
args: { | ||
porting: portingFactory.build(), | ||
}, | ||
} | ||
|
||
export const Primary = { | ||
export const PrefilledPorting = { | ||
args: { | ||
token: 'abc:123', | ||
initialPorting: portingFactory.build(), | ||
porting: portingFactory | ||
.params({ | ||
accountNumber: '1234', | ||
accountPinExists: true, | ||
birthday: '01.01.1990', | ||
firstName: 'Jane', | ||
lastName: 'Doe', | ||
}) | ||
.build(), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.