add error message handler, add request animation

This commit is contained in:
smanylov
2026-03-04 17:16:30 +07:00
parent a11abdbb56
commit b8c439d2d7
8 changed files with 65 additions and 14 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "no-copy-frontend", "name": "no-copy-frontend",
"version": "0.50.0", "version": "0.51.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 2999", "dev": "next dev -p 2999",
+31 -3
View File
@@ -619,16 +619,35 @@ export async function confirmPassword(
if (parsed.message_code === 0) { if (parsed.message_code === 0) {
await createSession(parsed.message_body.authToken, email as string); await createSession(parsed.message_body.authToken, email as string);
} else { } else {
throw parsed.message_body; throw parsed;
} }
} else { } else {
throw (`${response.status}`); throw (`${response.status}`);
} }
} catch (error: unknown) { } catch (error: unknown) {
const typedError = error as any;
const errors: Record<string, string> = {}; const errors: Record<string, string> = {};
if (error) { if (error) {
const typedError = error as any;
switch (typedError.message_code) {
case 1:
errors['server'] = 'unknown-error'
break
case 2:
if (typedError.message_desc === 'Token not found or time expired') {
errors['server'] = 'token-not-found-or-time-expired'
} else {
errors['server'] = 'unknown-error'
}
break;
default:
errors['server'] = 'request-ended-with-an-error'
break;
}
return { return {
previousState: { previousState: {
email, email,
@@ -639,7 +658,16 @@ export async function confirmPassword(
error: errors error: errors
}; };
} }
throw error;
return {
previousState: {
email,
password,
confirm_password,
verifyToken
},
error: errors
};
} }
redirect('/pages/dashboard'); redirect('/pages/dashboard');
@@ -115,7 +115,12 @@ export default function ConfirmMailModalWindow({ userId, email, onClose }: { use
className={`${styles['btn']}`} className={`${styles['btn']}`}
disabled={confirmCodeValue.length !== 6 || isPending} disabled={confirmCodeValue.length !== 6 || isPending}
> >
{isPending ? t('confirming') : t('confirm')} {t('confirm')}
{isPending && (
<div className="loading-animation">
<div className="global-spinner"></div>
</div>
)}
</button> </button>
<button <button
+10 -1
View File
@@ -31,8 +31,17 @@ export default function ForgotPasswordForm() {
</p> </p>
)} )}
</div> </div>
<button type="submit" className={`${styles['btn']}`}> <button
type="submit"
className={`${styles['btn']}`}
disabled={isPending}
>
{t('recover-password')} {t('recover-password')}
{isPending && (
<div className="loading-animation">
<div className="global-spinner"></div>
</div>
)}
</button> </button>
</form> </form>
) )
+13 -4
View File
@@ -194,13 +194,22 @@ export default function ResetPasswordForm() {
</p> </p>
)} )}
</div> </div>
{/* {state?.error.server && ( {formState?.error?.server && (
<p className={`${styles['form-error']}`}> <p className={`${styles['form-error']}`}>
{t(state?.error.server)} {t(formState?.error?.server)}
</p> </p>
)} */} )}
<button type="submit" className={`${styles['btn']}`}> <button
type="submit"
className={`${styles['btn']}`}
disabled={isPending}
>
{t('change-password')} {t('change-password')}
{isPending && (
<div className="loading-animation">
<div className="global-spinner"></div>
</div>
)}
</button> </button>
</form> </form>
) )
@@ -5,8 +5,6 @@ import { useTranslations } from 'next-intl';
export function FileInfoModalWindow({ fileInfo, setWindowClose, setWindowChildren }: any) { export function FileInfoModalWindow({ fileInfo, setWindowClose, setWindowChildren }: any) {
const t = useTranslations('Global'); const t = useTranslations('Global');
console.log(fileInfo);
return ( return (
<div className="modal-window-view-file"> <div className="modal-window-view-file">
<div className="modal-window-view-file-header"> <div className="modal-window-view-file-header">
+2 -1
View File
@@ -385,6 +385,7 @@
"company-already-registered": "The company is already registered.", "company-already-registered": "The company is already registered.",
"confirming" : "Confirming", "confirming" : "Confirming",
"server-error": "Server error", "server-error": "Server error",
"network-error": "Network error" "network-error": "Network error",
"token-not-found-or-time-expired": "Token not found or time expired"
} }
} }
+2 -1
View File
@@ -385,6 +385,7 @@
"company-already-registered": "Компания уже зарегистрирована.", "company-already-registered": "Компания уже зарегистрирована.",
"confirming": "Подтверждение", "confirming": "Подтверждение",
"server-error": "Ошибка сервера", "server-error": "Ошибка сервера",
"network-error": "Сетевая ошибка" "network-error": "Сетевая ошибка",
"token-not-found-or-time-expired": "Токен не найден или истек срок его действия."
} }
} }