-
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.
feat: postpone payment sub page (#340)
* Saving progress * Change from using hasTags instead of matches and simplify display of optional input description property. * Remove unused toggle function and useState. * Remove unused css class. * Remove unused imports. * Remove unused css class. * Fix after feedback. * Update bodywit context values. * Update export and import logic. * Extend validation logic to enable specifying multiple valid conditions. Also, move validation logic for travelGuarantee to seperate file. * Update translation strings. * Update state machine and form. * Replace old validator. * Remove description parameter from Input component. Will solve optinal description of input comonent in a seperate pr. * remove console.log * Fix minor typo, name imrovment and move travelGuaranteeFieldValidator into the dir special-field-validators to make the distinction between validation of common form fields and special cases more clear. * Update import/export of RefundForm and shouldShowContactPage. * update url to endpoint. * Update src/translations/pages/contact.ts Co-authored-by: Morten Nordseth <43166974+mortennordseth@users.noreply.github.com> --------- Co-authored-by: Morten Nordseth <43166974+mortennordseth@users.noreply.github.com>
- Loading branch information
1 parent
d8826c4
commit 1975878
Showing
15 changed files
with
601 additions
and
237 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 was deleted.
Oops, something went wrong.
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 @@ | ||
export { PostponePaymentForm } from './postpone-paymnet'; |
122 changes: 122 additions & 0 deletions
122
src/page-modules/contact/ticket-control/postpone-paymnet/index.tsx
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,122 @@ | ||
import { FormEventHandler, useState } from 'react'; | ||
import { Button } from '@atb/components/button'; | ||
import { Input } from '../../components/input'; | ||
import { SectionCard } from '../../components/section-card'; | ||
import { PageText, useTranslation } from '@atb/translations'; | ||
import { useMachine } from '@xstate/react'; | ||
import { postponePaymentForm } from './postponePaymentFormMachine'; | ||
|
||
export const PostponePaymentForm = () => { | ||
const { t } = useTranslation(); | ||
const [state, send] = useMachine(postponePaymentForm); | ||
|
||
// Local state to force re-render to display errors. | ||
const [forceRerender, setForceRerender] = useState(false); | ||
|
||
const onSubmit: FormEventHandler<HTMLFormElement> = async (e) => { | ||
e.preventDefault(); | ||
send({ type: 'VALIDATE' }); | ||
|
||
// Force a re-render with dummy state. | ||
if (Object.keys(state.context.errorMessages).length > 0) { | ||
setForceRerender(!forceRerender); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={onSubmit}> | ||
<SectionCard title={PageText.Contact.ticketControl.postponePayment.title}> | ||
<p>{t(PageText.Contact.ticketControl.postponePayment.info)}</p> | ||
|
||
<Input | ||
label={PageText.Contact.inputFields.feeNumber.label} | ||
type="text" | ||
name="feeNumber" | ||
value={state.context.feeNumber} | ||
errorMessage={ | ||
state.context?.errorMessages['feeNumber']?.[0] || undefined | ||
} | ||
onChange={(e) => | ||
send({ | ||
type: 'UPDATE_FIELD', | ||
field: 'feeNumber', | ||
value: e.target.value, | ||
}) | ||
} | ||
/> | ||
|
||
<Input | ||
label={PageText.Contact.inputFields.invoiceNumber.label} | ||
type="text" | ||
name="invoiceNumber" | ||
value={state.context.invoiceNumber} | ||
errorMessage={ | ||
state.context?.errorMessages['invoiceNumber']?.[0] || undefined | ||
} | ||
onChange={(e) => | ||
send({ | ||
type: 'UPDATE_FIELD', | ||
field: 'invoiceNumber', | ||
value: e.target.value, | ||
}) | ||
} | ||
/> | ||
</SectionCard> | ||
<SectionCard title={PageText.Contact.aboutYouInfo.title}> | ||
<Input | ||
label={PageText.Contact.inputFields.firstName.label} | ||
type="text" | ||
name="firstName" | ||
value={state.context.firstName} | ||
errorMessage={ | ||
state.context?.errorMessages['firstName']?.[0] || undefined | ||
} | ||
onChange={(e) => | ||
send({ | ||
type: 'UPDATE_FIELD', | ||
field: 'firstName', | ||
value: e.target.value, | ||
}) | ||
} | ||
/> | ||
<Input | ||
label={PageText.Contact.inputFields.lastName.label} | ||
type="text" | ||
name="lastName" | ||
value={state.context.lastName} | ||
errorMessage={ | ||
state.context?.errorMessages['lastName']?.[0] || undefined | ||
} | ||
onChange={(e) => | ||
send({ | ||
type: 'UPDATE_FIELD', | ||
field: 'lastName', | ||
value: e.target.value, | ||
}) | ||
} | ||
/> | ||
<Input | ||
label={PageText.Contact.inputFields.email.label} | ||
type="email" | ||
name="email" | ||
value={state.context.email} | ||
errorMessage={state.context?.errorMessages['email']?.[0] || undefined} | ||
onChange={(e) => | ||
send({ | ||
type: 'UPDATE_FIELD', | ||
field: 'email', | ||
value: e.target.value, | ||
}) | ||
} | ||
/> | ||
</SectionCard> | ||
<Button | ||
title={t(PageText.Contact.submit)} | ||
mode={'interactive_0--bordered'} | ||
buttonProps={{ type: 'submit' }} | ||
/> | ||
</form> | ||
); | ||
}; | ||
|
||
export default PostponePaymentForm; |
Oops, something went wrong.