-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(samgongustofa): Validate when buyer fields are empty in TransferO…
…fVehicleOwnership (#16999) * Validate buyer + buyerCoOwnerAndOperator in TransferOfVehicleOwnership * Validate added co-owners i ChangeCoOwnerOfVehicle * Fix getApproveAnswers for changeOperatorOfVehicle * Add error message if no changes in ChangeOperatorOfVehicle * Revert "Validate added co-owners i ChangeCoOwnerOfVehicle" This reverts commit 719277e. * Add error message if no changes in ChangeCoOwnerOfVehicle * Cleanup * Use watch instead of getApplicationInfo --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
204 additions
and
104 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
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
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
File renamed without changes.
63 changes: 63 additions & 0 deletions
63
...on/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/Buyer/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,63 @@ | ||
import { getValueViaPath } from '@island.is/application/core' | ||
import { FieldBaseProps } from '@island.is/application/types' | ||
import { Box } from '@island.is/island-ui/core' | ||
import { useLocale } from '@island.is/localization' | ||
import { FC, useState, useCallback, useEffect } from 'react' | ||
import { UserInformation } from '../../shared' | ||
import { useMutation } from '@apollo/client' | ||
import { UPDATE_APPLICATION } from '@island.is/application/graphql' | ||
import { BuyerItem } from './BuyerItem' | ||
|
||
const emailRegex = | ||
/^[\w!#$%&'*+/=?`{|}~^-]+(?:\.[\w!#$%&'*+/=?`{|}~^-]+)*@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$/i | ||
|
||
export const Buyer: FC<React.PropsWithChildren<FieldBaseProps>> = (props) => { | ||
const { locale } = useLocale() | ||
const { application, field } = props | ||
const { id } = field | ||
|
||
const [updateApplication] = useMutation(UPDATE_APPLICATION) | ||
|
||
const [buyer, setBuyer] = useState<UserInformation>( | ||
getValueViaPath(application.answers, 'buyer', { | ||
name: '', | ||
nationalId: '', | ||
phone: '', | ||
email: '', | ||
}) as UserInformation, | ||
) | ||
|
||
const updateBuyer = useCallback( | ||
async (buyer: UserInformation) => { | ||
await updateApplication({ | ||
variables: { | ||
input: { | ||
id: application.id, | ||
answers: { | ||
buyer: buyer, | ||
}, | ||
}, | ||
locale, | ||
}, | ||
}) | ||
}, | ||
[application.id, locale, updateApplication], | ||
) | ||
|
||
useEffect(() => { | ||
if ( | ||
buyer.name.length > 0 && | ||
buyer.nationalId.length === 10 && | ||
buyer.phone.length >= 7 && | ||
emailRegex.test(buyer.email) | ||
) { | ||
updateBuyer(buyer) | ||
} | ||
}, [buyer, updateBuyer]) | ||
|
||
return ( | ||
<Box> | ||
<BuyerItem id={id} buyer={buyer} setBuyer={setBuyer} {...props} /> | ||
</Box> | ||
) | ||
} |
File renamed without changes.
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.