From 777555c187449ef413d952fe48c846c10055441b Mon Sep 17 00:00:00 2001 From: smanylov Date: Thu, 5 Feb 2026 19:31:06 +0700 Subject: [PATCH] edit company-user registration --- src/app/actions/companyActions.ts | 50 +++++++++++++------ src/app/ui/inputs/phone-input.tsx | 13 +++-- .../settings/company-users-setting-panel.tsx | 12 ++++- .../ui/settings/personal-data-settings.tsx | 4 ++ 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/app/actions/companyActions.ts b/src/app/actions/companyActions.ts index d83f3cd..5182eae 100644 --- a/src/app/actions/companyActions.ts +++ b/src/app/actions/companyActions.ts @@ -1,8 +1,7 @@ 'use server' import { API_BASE_URL, getSignupFormSchema } from '@/app/actions/definitions'; -import { createSession } from '@/app/actions/session'; -import { redirect } from 'next/navigation'; +import { getSessionData } from '@/app/actions/session'; export type CompanyUserRegistrationFormState = { previousState: { @@ -12,6 +11,7 @@ export type CompanyUserRegistrationFormState = { confirm_password: string; phone: string; }, + createdUser: string | null error: Record | null } | undefined; @@ -19,6 +19,11 @@ export async function companyUserRegistration( state: CompanyUserRegistrationFormState | undefined, formData: FormData, ): Promise { + const token = await getSessionData('token'); + if (!token) { + return; + } + const fullName = formData.get('fullName') as string || ''; const email = formData.get('email') as string || ''; const password = formData.get('password') as string || ''; @@ -53,6 +58,7 @@ export async function companyUserRegistration( } }); + console.log('registration error'); console.log(errors); return { @@ -63,21 +69,11 @@ export async function companyUserRegistration( confirm_password, phone }, + createdUser: null, error: errors }; } - return { - previousState: { - fullName, - email, - password, - confirm_password, - phone - }, - error: null - }; - try { const { fullName, email, password, phone } = validatedFields.data; const response = await fetch(`${API_BASE_URL}/api/v1/data`, { @@ -89,7 +85,10 @@ export async function companyUserRegistration( fullName: fullName, email, phone: phone, - password + password, + accountType: 'b2b', + authToken: token, + companyName: '' } }), headers: { @@ -104,6 +103,14 @@ export async function companyUserRegistration( message_body: { token: string }, message_code: number }; + console.log({ + fullName: fullName, + email, + phone: phone, + password, + accountType: 'b2b', + authToken: token + }); if (parsed.message_code === 0) { console.log(`registration - ${email}`); @@ -113,7 +120,18 @@ export async function companyUserRegistration( phone: phone, password }); - await createSession(parsed.message_body.token, email as string); + + return { + previousState: { + fullName: '', + email: '', + password: '', + confirm_password: '', + phone: '' + }, + createdUser: fullName, + error: null + } } else { throw parsed; } @@ -162,6 +180,7 @@ export async function companyUserRegistration( confirm_password, phone }, + createdUser: null, error: errors }; } @@ -174,6 +193,7 @@ export async function companyUserRegistration( confirm_password, phone }, + createdUser: null, error: errors }; } diff --git a/src/app/ui/inputs/phone-input.tsx b/src/app/ui/inputs/phone-input.tsx index cb3a4cf..f3191e0 100644 --- a/src/app/ui/inputs/phone-input.tsx +++ b/src/app/ui/inputs/phone-input.tsx @@ -1,16 +1,23 @@ 'use client' -import { useState, ChangeEvent } from 'react'; +import { useState, ChangeEvent, useEffect } from 'react'; import { InputMask } from '@react-input/mask'; import styles from '@/app/styles/module/login.module.scss'; interface PhoneInputProps { phoneState: string | undefined; validateHandler: (e: ChangeEvent) => void; + clearCondition?: string | undefined | null } -export default function PhoneInput({ phoneState, validateHandler }: PhoneInputProps) { - const [phone, setPhone] = useState(phoneState ? phoneState : ''); +export default function PhoneInput({ phoneState, validateHandler, clearCondition }: PhoneInputProps) { + const [phone, setPhone] = useState(phoneState ? phoneState : ''); + + useEffect(() => { + if (clearCondition) { + setPhone(''); + } + }, [clearCondition]) return ( { if (state) { setFormState(state); + if (state.createdUser) { + toast.success(`Создан пользователь - ${state.createdUser}`); + } } }, [state]) @@ -84,7 +88,6 @@ export function CompanyUsersSettingPanel() { case 'agree': const schema = SignupFormSchema.shape[fieldName]; if (fieldName === 'phone') { - console.log(schema.safeParse(value.replace(/[-\(\)\s]/g, ''))); return schema.safeParse(value.replace(/[-\(\)\s]/g, '')); } if (fieldName === 'companyName') { @@ -204,6 +207,7 @@ export function CompanyUsersSettingPanel() { {formState?.error?.phone && (

@@ -294,6 +298,12 @@ export function CompanyUsersSettingPanel() { )} + {formState?.error?.server && ( +

+ {t(formState?.error?.server)} +

+ )} + diff --git a/src/app/ui/settings/personal-data-settings.tsx b/src/app/ui/settings/personal-data-settings.tsx index 4eb4205..8e4086c 100644 --- a/src/app/ui/settings/personal-data-settings.tsx +++ b/src/app/ui/settings/personal-data-settings.tsx @@ -25,6 +25,10 @@ export default function PersonalDataSettings() { } }); + useEffect(() => { + console.log(userData) + }, [userData]); + const t = useTranslations('Global'); return (