-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
add pin fields to the reset password page
- Loading branch information
Showing
3 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
.../(guest)/reset-password/_components/reset-password-form/_components/confirm-pin-field.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,61 @@ | ||
import { Input } from '@nextui-org/react' | ||
import { Eye, EyeOff } from 'lucide-react' | ||
import { usePinVisibilityState } from '../_stores/pin-visibility' | ||
import { useFormSubmissionState } from '@/stores/form-submission' | ||
import { useErrorMessageState } from '@/stores/input-error-message' | ||
import { FormEvent } from 'react' | ||
|
||
export default function ConfirmPinField() { | ||
// Stores | ||
const { isSubmitting } = useFormSubmissionState() | ||
const { isVisible, toggleVisibility } = usePinVisibilityState( | ||
state => state.confirmPin, | ||
) | ||
const { fields } = useErrorMessageState() | ||
|
||
const errorMessage = fields.find( | ||
field => field.identifier === 'confirm_pin', | ||
)?.message | ||
|
||
const handleInput = (event: FormEvent<HTMLInputElement>) => { | ||
const element = event.target as HTMLInputElement | ||
const value = element.value | ||
|
||
if (!/^\d*$/.test(value)) { | ||
element.value = value.replace(/[^\d]/g, '') | ||
} | ||
|
||
if (element.value.length > 6) { | ||
element.value = element.value.slice(0, 6) | ||
} | ||
} | ||
|
||
return ( | ||
<Input | ||
label="Konfirmasi PIN Baru" | ||
name="confirm_pin" | ||
isRequired | ||
isDisabled={isSubmitting} | ||
isInvalid={!!errorMessage} | ||
errorMessage={errorMessage} | ||
inputMode="numeric" | ||
pattern="\d{6}" | ||
onInput={handleInput} | ||
endContent={ | ||
<button | ||
tabIndex={-1} | ||
className="focus:outline-none" | ||
type="button" | ||
onClick={() => toggleVisibility()} | ||
aria-label="toggle confirm-pin visibility"> | ||
{isVisible ? ( | ||
<EyeOff className="pointer-events-none text-2xl text-default-400" /> | ||
) : ( | ||
<Eye className="pointer-events-none text-2xl text-default-400" /> | ||
)} | ||
</button> | ||
} | ||
type={isVisible ? 'text' : 'password'} | ||
/> | ||
) | ||
} |
58 changes: 58 additions & 0 deletions
58
src/app/(guest)/reset-password/_components/reset-password-form/_components/pin-field.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,58 @@ | ||
import { Input } from '@nextui-org/react' | ||
import { Eye, EyeOff } from 'lucide-react' | ||
import { usePinVisibilityState } from '../_stores/pin-visibility' | ||
import { useFormSubmissionState } from '@/stores/form-submission' | ||
import { useErrorMessageState } from '@/stores/input-error-message' | ||
import { FormEvent } from 'react' | ||
|
||
export default function PinField() { | ||
// Stores | ||
const { isSubmitting } = useFormSubmissionState() | ||
const { isVisible, toggleVisibility } = usePinVisibilityState( | ||
state => state.pin, | ||
) | ||
const { fields } = useErrorMessageState() | ||
|
||
const errorMessage = fields.find(field => field.identifier === 'pin')?.message | ||
|
||
const handleInput = (event: FormEvent<HTMLInputElement>) => { | ||
const element = event.target as HTMLInputElement | ||
const value = element.value | ||
|
||
if (!/^\d*$/.test(value)) { | ||
element.value = value.replace(/[^\d]/g, '') | ||
} | ||
|
||
if (element.value.length > 6) { | ||
element.value = element.value.slice(0, 6) | ||
} | ||
} | ||
|
||
return ( | ||
<Input | ||
label="PIN Baru" | ||
name="pin" | ||
isRequired | ||
isDisabled={isSubmitting} | ||
isInvalid={!!errorMessage} | ||
errorMessage={errorMessage} | ||
inputMode="numeric" | ||
onInput={handleInput} | ||
endContent={ | ||
<button | ||
tabIndex={-1} | ||
className="focus:outline-none" | ||
type="button" | ||
onClick={() => toggleVisibility()} | ||
aria-label="toggle pin visibility"> | ||
{isVisible ? ( | ||
<EyeOff className="pointer-events-none text-2xl text-default-400" /> | ||
) : ( | ||
<Eye className="pointer-events-none text-2xl text-default-400" /> | ||
)} | ||
</button> | ||
} | ||
type={isVisible ? 'text' : 'password'} | ||
/> | ||
) | ||
} |
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