-
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: modify dfns modal form and config
- Loading branch information
1 parent
b8335b8
commit ada07dd
Showing
15 changed files
with
139 additions
and
61 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
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 |
---|---|---|
|
@@ -2,17 +2,29 @@ import { Button, FormControl, FormErrorMessage, FormLabel, Input, VStack } from | |
import { useForm } from '@tanstack/react-form'; | ||
|
||
interface DFNSModalLoginFormProps { | ||
onSubmit: (username: string, organizationID: string) => Promise<void>; | ||
onSubmit: (email: string) => Promise<void>; | ||
} | ||
|
||
const validateEmail = (email: string) => { | ||
if (!email) return 'Email address is required'; | ||
|
||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
if (!emailRegex.test(email)) return 'Please enter a valid email address'; | ||
|
||
const [localPart] = email.split('@'); | ||
if (localPart.length > 64) return 'Local part of email cannot exceed 64 characters'; | ||
if (email.length > 254) return 'Email address cannot exceed 254 characters'; | ||
|
||
return undefined; | ||
}; | ||
|
||
export function DFNSModalLoginForm({ onSubmit }: DFNSModalLoginFormProps): React.JSX.Element { | ||
const formAPI = useForm({ | ||
defaultValues: { | ||
username: '', | ||
organizationId: '', | ||
email: '', | ||
}, | ||
onSubmit: async ({ value }) => { | ||
await onSubmit(value.username, value.organizationId); | ||
await onSubmit(value.email); | ||
}, | ||
}); | ||
|
||
|
@@ -27,43 +39,18 @@ export function DFNSModalLoginForm({ onSubmit }: DFNSModalLoginFormProps): React | |
> | ||
<VStack spacing={4} w={'100%'}> | ||
<formAPI.Field | ||
name="username" | ||
name="email" | ||
validators={{ | ||
onChange: ({ value }) => { | ||
if (!value) return 'Username is required'; | ||
if (value.length < 3) return 'Username must be at least 3 characters'; | ||
return undefined; | ||
}, | ||
onChange: ({ value }) => validateEmail(value), | ||
}} | ||
children={field => ( | ||
<FormControl isInvalid={!!field.state.meta.errorMap.onChange}> | ||
<FormLabel>Username</FormLabel> | ||
<FormLabel>E-Mail Address</FormLabel> | ||
<Input | ||
type="email" | ||
value={field.state.value} | ||
onChange={e => field.handleChange(e.target.value)} | ||
placeholder="[email protected]" | ||
/> | ||
<FormErrorMessage>{field.state.meta.errorMap.onChange}</FormErrorMessage> | ||
</FormControl> | ||
)} | ||
/> | ||
|
||
<formAPI.Field | ||
name="organizationId" | ||
validators={{ | ||
onChange: ({ value }) => { | ||
if (!value) return 'Organization ID is required'; | ||
return undefined; | ||
}, | ||
}} | ||
children={field => ( | ||
<FormControl isInvalid={!!field.state.meta.errorMap.onChange}> | ||
<FormLabel>Organization ID</FormLabel> | ||
<Input | ||
value={field.state.value} | ||
onChange={e => field.handleChange(e.target.value)} | ||
placeholder="Enter organization ID" | ||
placeholder="[email protected]" | ||
/> | ||
<FormErrorMessage>{field.state.meta.errorMap.onChange}</FormErrorMessage> | ||
</FormControl> | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5220,8 +5220,10 @@ dir-glob@^3.0.1: | |
dependencies: | ||
path-type "^4.0.0" | ||
|
||
"dlc-btc-lib@file:../dlc-btc-lib": | ||
version "2.4.10" | ||
[email protected]: | ||
version "2.4.19-dfns-beta" | ||
resolved "https://registry.yarnpkg.com/dlc-btc-lib/-/dlc-btc-lib-2.4.19-dfns-beta.tgz#4d9ddb7591a0d3f5cc99d09a7e25cea7aece77e3" | ||
integrity sha512-niqR5KixLyrxgR91DzcDfpb5sW7IEWtHqpsLRTFFI679hcPabglYI5l5NsNc6UZ08DHI7ecd2/ZKnEXlMMxCpg== | ||
dependencies: | ||
"@dfns/sdk" "^0.5.9" | ||
"@dfns/sdk-browser" "^0.5.9" | ||
|