add confirm email modal window
This commit is contained in:
+30
-4
@@ -1,7 +1,7 @@
|
|||||||
'use server'
|
'use server'
|
||||||
|
|
||||||
import { loginFormSchema, API_BASE_URL, getSignupFormSchema } from '@/app/actions/definitions';
|
import { loginFormSchema, API_BASE_URL, getSignupFormSchema } from '@/app/actions/definitions';
|
||||||
import {createSession, deleteSession, getSessionData, updateSession} from '@/app/actions/session';
|
import { createSession, deleteSession, getSessionData, updateSession } from '@/app/actions/session';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
export async function logout() {
|
export async function logout() {
|
||||||
@@ -138,8 +138,9 @@ export type FormState = {
|
|||||||
phone: string;
|
phone: string;
|
||||||
companyName: string;
|
companyName: string;
|
||||||
agree: string;
|
agree: string;
|
||||||
}
|
},
|
||||||
error: Record<string, string>
|
mailConfirm?: boolean,
|
||||||
|
error: Record<string, string> | null
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function registration(
|
export async function registration(
|
||||||
@@ -230,6 +231,20 @@ export async function registration(
|
|||||||
} else {
|
} else {
|
||||||
throw (`${response.status}`);
|
throw (`${response.status}`);
|
||||||
}
|
}
|
||||||
|
console.log('/v1');
|
||||||
|
return {
|
||||||
|
previousState: {
|
||||||
|
fullName,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
confirm_password,
|
||||||
|
phone,
|
||||||
|
companyName,
|
||||||
|
agree
|
||||||
|
},
|
||||||
|
mailConfirm: true,
|
||||||
|
error: null
|
||||||
|
};
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error) {
|
if (error) {
|
||||||
const typedError = error as any;
|
const typedError = error as any;
|
||||||
@@ -275,7 +290,9 @@ export async function registration(
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect('/pages/dashboard');
|
/* redirect('/pages/dashboard'); */
|
||||||
|
/* console.log('/v2');
|
||||||
|
redirect('/v2'); */
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function tokenLifeExtension() {
|
export async function tokenLifeExtension() {
|
||||||
@@ -307,3 +324,12 @@ export async function tokenLifeExtension() {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function confirmEmail(
|
||||||
|
state: any | undefined,
|
||||||
|
formData: any,
|
||||||
|
) {
|
||||||
|
console.log('confirmEmail');
|
||||||
|
const emailConfirm = formData.get('emailConfirm') as string || '';
|
||||||
|
console.log(emailConfirm);
|
||||||
|
}
|
||||||
@@ -41,6 +41,9 @@
|
|||||||
|
|
||||||
.form-group {
|
.form-group {
|
||||||
margin-bottom: 18px;
|
margin-bottom: 18px;
|
||||||
|
|
||||||
|
&-confrim-window {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-row {
|
.form-row {
|
||||||
@@ -139,6 +142,12 @@
|
|||||||
margin: 20px 0 0 0;
|
margin: 20px 0 0 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-group-confrim-window {
|
||||||
|
.btn {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.register-link {
|
.register-link {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: 18px;
|
margin-top: 18px;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import styles from '@/app/styles/module/login.module.scss';
|
import styles from '@/app/styles/module/login.module.scss';
|
||||||
import { ChangeEvent, useActionState, useEffect, useRef, useState } from 'react';
|
import { ChangeEvent, useActionState, useEffect, useRef, useState } from 'react';
|
||||||
import { registration, FormState } from '@/app/actions/auth';
|
import { registration, FormState, confirmEmail } from '@/app/actions/auth';
|
||||||
import PhoneInput from '@/app/ui/inputs/phone-input';
|
import PhoneInput from '@/app/ui/inputs/phone-input';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
@@ -16,14 +16,24 @@ export default function RegisterForm() {
|
|||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [stateEmailConfrim, formActionEmailConfrim, isPendingEmailConfrim] = useActionState(
|
||||||
|
confirmEmail,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
|
||||||
const t = useTranslations('Login-register-form');
|
const t = useTranslations('Login-register-form');
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
||||||
const [formState, setFormState] = useState<FormState | undefined>(undefined);
|
const [formState, setFormState] = useState<FormState | undefined>(undefined);
|
||||||
|
const [showMailConfirmWindow, setShowMailConfirmWindow] = useState(false);
|
||||||
const passwordRef = useRef<HTMLInputElement>(null);
|
const passwordRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFormState(state);
|
setFormState(state);
|
||||||
|
if (state?.mailConfirm) {
|
||||||
|
setShowMailConfirmWindow(true);
|
||||||
|
}
|
||||||
|
|
||||||
}, [state])
|
}, [state])
|
||||||
|
|
||||||
function showPassowrd(target: 'password' | 'confirm-password') {
|
function showPassowrd(target: 'password' | 'confirm-password') {
|
||||||
@@ -104,6 +114,52 @@ export default function RegisterForm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{showMailConfirmWindow && (
|
||||||
|
<div
|
||||||
|
className="modal-wrapper"
|
||||||
|
onClick={() => {
|
||||||
|
setShowMailConfirmWindow(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="modal-window"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
<div className={`${styles['form-group']} ${styles['form-group-confrim-window']}`}>
|
||||||
|
<form action={(e) => {
|
||||||
|
formActionEmailConfrim(e);
|
||||||
|
}}>
|
||||||
|
<div className={`${styles['form-group']}`}>
|
||||||
|
<h4
|
||||||
|
className="mb-6"
|
||||||
|
>
|
||||||
|
{t('enter-confirmation-code')}
|
||||||
|
</h4>
|
||||||
|
<label
|
||||||
|
className={`${styles['form-label']}`}
|
||||||
|
>
|
||||||
|
{t('confirmation-code')}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="emailConfirm"
|
||||||
|
name="emailConfirm"
|
||||||
|
className={`${styles['form-input']}`}
|
||||||
|
placeholder="mail-code"
|
||||||
|
defaultValue=""
|
||||||
|
onChange={(e) => {
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button type="submit" className={`${styles['btn']}`}>
|
||||||
|
Проверить
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<form action={(e) => {
|
<form action={(e) => {
|
||||||
formAction(e);
|
formAction(e);
|
||||||
}}>
|
}}>
|
||||||
@@ -330,5 +386,6 @@ export default function RegisterForm() {
|
|||||||
{t('create-an-account')}
|
{t('create-an-account')}
|
||||||
</button>
|
</button>
|
||||||
</form >
|
</form >
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -235,6 +235,8 @@
|
|||||||
"password-too-common": "This password is too common, please choose another.",
|
"password-too-common": "This password is too common, please choose another.",
|
||||||
"register-error-email-min": "Email length must be at least 7 characters.",
|
"register-error-email-min": "Email length must be at least 7 characters.",
|
||||||
"register-error-phone-not-allowed-symbols": "",
|
"register-error-phone-not-allowed-symbols": "",
|
||||||
"register-error-password-not-allowed-symbols": "Password contains invalid characters."
|
"register-error-password-not-allowed-symbols": "Password contains invalid characters.",
|
||||||
|
"confirmation-code": "Confirmation code",
|
||||||
|
"enter-confirmation-code": "Enter the confirmation code"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,6 +235,8 @@
|
|||||||
"password-too-common": "Этот пароль слишком простой, пожалуйста, выберите другой.",
|
"password-too-common": "Этот пароль слишком простой, пожалуйста, выберите другой.",
|
||||||
"register-error-email-min": "Длина Email не должна быть меньше 7 символов.",
|
"register-error-email-min": "Длина Email не должна быть меньше 7 символов.",
|
||||||
"register-error-phone-not-allowed-symbols": "",
|
"register-error-phone-not-allowed-symbols": "",
|
||||||
"register-error-password-not-allowed-symbols": "Пароль содержит недопустимые символы."
|
"register-error-password-not-allowed-symbols": "Пароль содержит недопустимые символы.",
|
||||||
|
"confirmation-code": "Код подтверждения",
|
||||||
|
"enter-confirmation-code": "Введите код подтверждения"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user