add confirm mail modal window
This commit is contained in:
+94
-17
@@ -139,6 +139,7 @@ export type FormState = {
|
|||||||
agree: string;
|
agree: string;
|
||||||
},
|
},
|
||||||
mailConfirm?: boolean,
|
mailConfirm?: boolean,
|
||||||
|
userId?: number,
|
||||||
error: Record<string, string> | null
|
error: Record<string, string> | null
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -219,11 +220,27 @@ export async function registration(
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
let parsed = await response.json() as {
|
let parsed = await response.json() as {
|
||||||
message_desc: string,
|
message_desc: string,
|
||||||
message_body: { token: string },
|
message_body: { token: string, userId: number },
|
||||||
message_code: string
|
message_code: string
|
||||||
};
|
};
|
||||||
|
console.log(parsed);
|
||||||
if (parsed.message_desc === 'Operation successful') {
|
if (parsed.message_desc === 'Operation successful') {
|
||||||
await createSession(parsed.message_body.token, email as string);
|
|
||||||
|
/* await createSession(parsed.message_body.token, email as string); */
|
||||||
|
return {
|
||||||
|
previousState: {
|
||||||
|
fullName,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
confirm_password,
|
||||||
|
phone,
|
||||||
|
companyName,
|
||||||
|
agree
|
||||||
|
},
|
||||||
|
mailConfirm: true,
|
||||||
|
userId: parsed.message_body.userId,
|
||||||
|
error: null
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
throw parsed;
|
throw parsed;
|
||||||
}
|
}
|
||||||
@@ -231,19 +248,6 @@ export async function registration(
|
|||||||
throw (`${response.status}`);
|
throw (`${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
||||||
@@ -282,6 +286,7 @@ export async function registration(
|
|||||||
companyName,
|
companyName,
|
||||||
agree
|
agree
|
||||||
},
|
},
|
||||||
|
mailConfirm: false,
|
||||||
error: errors
|
error: errors
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -327,9 +332,81 @@ export async function tokenLifeExtension() {
|
|||||||
|
|
||||||
export async function confirmEmail(
|
export async function confirmEmail(
|
||||||
state: any | undefined,
|
state: any | undefined,
|
||||||
formData: any,
|
formData: any
|
||||||
) {
|
) {
|
||||||
console.log('confirmEmail');
|
console.log('confirmEmail');
|
||||||
const emailConfirm = formData.get('emailConfirm') as string || '';
|
const emailConfirm = formData.get('emailConfirm') as string || '';
|
||||||
console.log(emailConfirm);
|
const userId = formData.get('userId') as string || '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 20009,
|
||||||
|
message_body: {
|
||||||
|
resend: 0,
|
||||||
|
user_id: userId,
|
||||||
|
verify_token: emailConfirm
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
console.log(parsed);
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
await createSession(parsed.message_body.token, parsed.message_body.email as string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
error: 'error'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redirect('/pages/dashboard');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resendConfirmEmail(userId: number) {
|
||||||
|
console.log('resendConfirmEmail');
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
version: 1,
|
||||||
|
msg_id: 20009,
|
||||||
|
message_body: {
|
||||||
|
resend: 1,
|
||||||
|
user_id: userId,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const parsed = await response.json();
|
||||||
|
console.log(parsed);
|
||||||
|
|
||||||
|
if (parsed.message_code === 0) {
|
||||||
|
return {
|
||||||
|
fine: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
fine: false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
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, MouseEvent } from 'react';
|
||||||
import { registration, FormState, confirmEmail } from '@/app/actions/auth';
|
import { registration, FormState, confirmEmail, resendConfirmEmail } 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';
|
||||||
@@ -113,8 +113,23 @@ export default function RegisterForm() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function reSendEmailConfirmCode(e: MouseEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log(state?.userId ? state?.userId : '');
|
||||||
|
if (state?.userId) {
|
||||||
|
await resendConfirmEmail(state?.userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setShowMailConfirmWindow(!showMailConfirmWindow)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
show modal
|
||||||
|
</button>
|
||||||
{showMailConfirmWindow && (
|
{showMailConfirmWindow && (
|
||||||
<div
|
<div
|
||||||
className="modal-wrapper"
|
className="modal-wrapper"
|
||||||
@@ -151,10 +166,31 @@ export default function RegisterForm() {
|
|||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<input
|
||||||
|
type="hiden"
|
||||||
|
id="userId"
|
||||||
|
name="userId"
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
defaultValue={state?.userId ? state?.userId : ''}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" className={`${styles['btn']}`}>
|
<div>
|
||||||
Проверить
|
{stateEmailConfrim?.error}
|
||||||
</button>
|
</div>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<button type="submit" className={`${styles['btn']}`}>
|
||||||
|
Проверить
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`${styles['btn']}`}
|
||||||
|
onClick={(e) => {
|
||||||
|
reSendEmailConfirmCode(e);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
test
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user