'use client'
import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useRouter } from 'next/navigation'
import Toast from '../components/base/toast'
import Loading from '../components/base/loading'
import Button from '@/app/components/base/button'
import { fetchInitValidateStatus, initValidate } from '@/service/common'
import type { InitValidateStatusResponse } from '@/models/common'
const InitPasswordPopup = () => {
const [password, setPassword] = useState('')
const [loading, setLoading] = useState(true)
const [validated, setValidated] = useState(false)
const router = useRouter()
const { t } = useTranslation()
const handleValidation = async () => {
setLoading(true)
try {
const response = await initValidate({ body: { password } })
if (response.result === 'success') {
setValidated(true)
router.push('/install') // or render setup form
}
else {
throw new Error('Validation failed')
}
}
catch (e: any) {
Toast.notify({
type: 'error',
message: e.message,
duration: 5000,
})
setLoading(false)
}
}
useEffect(() => {
fetchInitValidateStatus().then((res: InitValidateStatusResponse) => {
if (res.status === 'finished')
window.location.href = '/install'
else
setLoading(false)
})
}, [])
return (
loading
?