Skip to content

Commit

Permalink
Membangun Antarmuka Halaman Lupa Kata Sandi (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
theozebua authored Oct 4, 2024
1 parent 73db4db commit d85a6a8
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/app/(guest)/forgot-password/_components/email-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Button, Input } from '@nextui-org/react'
import { FormEvent, useState } from 'react'

export default function EmailForm() {
const [isLoading, setIsLoading] = useState(false)
const [hasValidEmail, setHasValidEmail] = useState(false)

const handleForgotPasswordByEmail = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault()

setIsLoading(true)

setTimeout(() => {
setIsLoading(false)
}, 2000)
}

return (
<>
<div className="mx-auto mb-4 max-w-xs">
<span className="block text-center text-sm">
Kirim Tautan Untuk Mengatur Ulang Kata Sandi
</span>
</div>

<form onSubmit={handleForgotPasswordByEmail} className="space-y-4">
<Input
onChange={event =>
setHasValidEmail(
event.target.value !== '' && event.target.validity.valid,
)
}
type="email"
label="Surel"
/>

<Button
color="primary"
className="w-full"
isDisabled={!hasValidEmail}
isLoading={isLoading}
type="submit">
Kirim Tautan
</Button>
</form>
</>
)
}
74 changes: 74 additions & 0 deletions src/app/(guest)/forgot-password/_components/security-question.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { User, users } from '@/data/users'
import {
Autocomplete,
AutocompleteItem,
Button,
Input,
} from '@nextui-org/react'
import { UserRound } from 'lucide-react'
import { FormEvent, useState } from 'react'

export default function SecurityQuestionForm() {
const [hasSelectedUser, setHasSelectedUser] = useState(false)
const [isLoading, setIsLoading] = useState(false)

const toggleHasSelectedUser = (key: string | number | null) =>
setHasSelectedUser(!!key)

const handleForgotPasswordBySecurityQuestion = (
event: FormEvent<HTMLFormElement>,
) => {
event.preventDefault()

setIsLoading(true)

setTimeout(() => {
setIsLoading(false)
}, 2000)
}

return (
<>
<div className="mx-auto mb-4 max-w-xs">
<span className="block text-center text-sm">
Jawab Pertanyaan Keamanan Untuk Mengatur Ulang Kata Sandi
</span>
</div>
<form
onSubmit={handleForgotPasswordBySecurityQuestion}
className="space-y-4">
<Autocomplete
label="Pilih Pengguna"
onSelectionChange={toggleHasSelectedUser}
isRequired>
{users.map((user: User) => (
<AutocompleteItem
key={user.id}
startContent={
<UserRound size={24} className="text-primary-300" />
}>
{user.name}
</AutocompleteItem>
))}
</Autocomplete>

{hasSelectedUser && (
<>
<Input type="text" label="Nama Ibu Kandung" />

<Input type="text" label="Nama Panggilan Masa Kecil" />
</>
)}

<Button
color="primary"
className="w-full"
isDisabled={!hasSelectedUser}
isLoading={isLoading}
type="submit">
Proses
</Button>
</form>
</>
)
}
38 changes: 36 additions & 2 deletions src/app/(guest)/forgot-password/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
'use client'

import { Card, CardBody, CardHeader, Divider } from '@nextui-org/react'
import EmailForm from './_components/email-form'
import SecurityQuestionForm from './_components/security-question'
import Link from 'next/link'
import PageUrlEnum from '@/enums/page-url'
import { useSearchParams } from 'next/navigation'

export default function Page() {
const query = useSearchParams()
const selectedMethod = query.get('method')

return (
<div>
<div>(Halaman Lupa Kata Sandi)</div>
<div className="container mt-8">
<div className="flex justify-center">
<Card className="max-w-md md:min-w-[400px]">
<CardHeader>
<span className="mx-auto block text-xl font-bold">
Lupa Kata Sandi
</span>
</CardHeader>
<Divider />
<CardBody>
{selectedMethod === 'security-question' ? (
<SecurityQuestionForm />
) : (
<EmailForm />
)}

<Link
className="mt-4 block cursor-pointer text-center text-sm outline-none"
href={`${PageUrlEnum.FORGOT_PASSWORD}?method=${selectedMethod === 'security-question' ? 'email' : 'security-question'}`}>
Coba Cara Lain?
</Link>
</CardBody>
</Card>
</div>
</div>
)
}
8 changes: 8 additions & 0 deletions src/app/(guest)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'

import { User, users } from '@/data/users'
import PageUrlEnum from '@/enums/page-url'
import {
Autocomplete,
AutocompleteItem,
Expand All @@ -12,6 +13,7 @@ import {
Input,
} from '@nextui-org/react'
import { Eye, EyeOff, UserRound } from 'lucide-react'
import Link from 'next/link'
import { FormEvent, useState } from 'react'

export default function Page() {
Expand Down Expand Up @@ -88,6 +90,12 @@ export default function Page() {
type="submit">
Masuk
</Button>

<Link
href={`${PageUrlEnum.FORGOT_PASSWORD}?method=email`}
className="my-4 block text-center text-sm">
Lupa Kata Sandi?
</Link>
</form>
</CardBody>
</Card>
Expand Down

0 comments on commit d85a6a8

Please sign in to comment.