feature: localization's first implmentation done. all frontend hardcoded text is now localized.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { Suspense } from 'react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { Link, useRouter } from '@/i18n/navigation';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { Button } from '@/components/ui/shared/Button';
|
||||
@@ -9,6 +10,7 @@ import { Input } from '@/components/ui/shared/Input';
|
||||
import { staffApi } from '@/lib/api/staff';
|
||||
|
||||
function AcceptInviteContent() {
|
||||
const t = useTranslations('auth');
|
||||
const params = useSearchParams();
|
||||
const router = useRouter();
|
||||
const token = useMemo(() => params.get('token') || '', [params]);
|
||||
@@ -32,7 +34,7 @@ function AcceptInviteContent() {
|
||||
useEffect(() => {
|
||||
if (!token) {
|
||||
setLoading(false);
|
||||
setError('Invalid invitation link');
|
||||
setError(t('invalidInvitationLink'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,30 +46,31 @@ function AcceptInviteContent() {
|
||||
setInviteInfo(res.data);
|
||||
setName(res.data.name || '');
|
||||
if (res.data.status === 'ACCEPTED') {
|
||||
setSuccess('This invitation is already accepted. You can log in now.');
|
||||
setSuccess(t('invitationAlreadyAccepted'));
|
||||
}
|
||||
} catch (e: any) {
|
||||
setError(e?.message || 'Could not load invitation');
|
||||
} catch (e: unknown) {
|
||||
const message = e && typeof e === 'object' && 'message' in e ? String(e.message) : '';
|
||||
setError(message || t('errorLoadInvitation'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
})();
|
||||
}, [token]);
|
||||
}, [token, t]);
|
||||
|
||||
async function onAccept() {
|
||||
if (!token) return;
|
||||
setError('');
|
||||
setSuccess('');
|
||||
if (!name.trim()) {
|
||||
setError('Name is required');
|
||||
setError(t('nameRequired'));
|
||||
return;
|
||||
}
|
||||
if (password.length < 8) {
|
||||
setError('Password must be at least 8 characters');
|
||||
setError(t('passwordMinLength8'));
|
||||
return;
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
setError('Passwords do not match');
|
||||
setError(t('passwordsDoNotMatch'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,12 +81,13 @@ function AcceptInviteContent() {
|
||||
name: name.trim(),
|
||||
password,
|
||||
});
|
||||
setSuccess('Invitation Accepted. Redirecting to login...');
|
||||
setSuccess(t('invitationAcceptedRedirect'));
|
||||
setTimeout(() => {
|
||||
router.replace('/login');
|
||||
}, 1000);
|
||||
} catch (e: any) {
|
||||
setError(e?.message || 'Could not accept invitation');
|
||||
} catch (e: unknown) {
|
||||
const message = e && typeof e === 'object' && 'message' in e ? String(e.message) : '';
|
||||
setError(message || t('errorAcceptInvitation'));
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
@@ -92,19 +96,21 @@ function AcceptInviteContent() {
|
||||
return (
|
||||
<div className="min-h-screen app-web-bg flex items-center justify-center p-4">
|
||||
<div className="w-full max-w-md surface-card p-6 space-y-5">
|
||||
<h1 className="text-xl font-semibold text-text-primary">Accept invitation</h1>
|
||||
<h1 className="text-xl font-semibold text-text-primary">{t('acceptInviteTitle')}</h1>
|
||||
|
||||
{loading ? (
|
||||
<p className="text-sm text-text-secondary">Loading invitation...</p>
|
||||
<p className="text-sm text-text-secondary">{t('loadingInvitation')}</p>
|
||||
) : (
|
||||
<>
|
||||
{inviteInfo && (
|
||||
<div className="rounded-[var(--radius-md)] border border-border/70 bg-background-secondary/70 px-3 py-2 text-sm text-text-secondary space-y-1">
|
||||
<p>
|
||||
Organization: <span className="text-text-primary">{inviteInfo.organizationName}</span>
|
||||
{t('organizationLabel')}{' '}
|
||||
<span className="text-text-primary">{inviteInfo.organizationName}</span>
|
||||
</p>
|
||||
<p>
|
||||
Email: <span className="text-text-primary">{inviteInfo.email}</span>
|
||||
{t('emailLabel')}{' '}
|
||||
<span className="text-text-primary">{inviteInfo.email}</span>
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
@@ -122,27 +128,28 @@ function AcceptInviteContent() {
|
||||
|
||||
{inviteInfo?.status !== 'ACCEPTED' && (
|
||||
<div className="space-y-3">
|
||||
<Input label="Name" value={name} onChange={(e) => setName(e.target.value)} />
|
||||
<Input label={t('labelName')} value={name} onChange={(e) => setName(e.target.value)} />
|
||||
<Input
|
||||
label="Create password"
|
||||
label={t('labelCreatePassword')}
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Confirm password"
|
||||
label={t('labelConfirmPassword')}
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
/>
|
||||
<Button type="button" fullWidth isLoading={submitting} onClick={() => void onAccept()}>
|
||||
Activate account
|
||||
{t('activateAccount')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<p className="text-xs text-text-muted">
|
||||
Already have access? <Link href="/login" className="text-primary">Go to login</Link>
|
||||
{t('alreadyHaveAccess')}{' '}
|
||||
<Link href="/login" className="text-primary">{t('goToLogin')}</Link>
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
@@ -151,15 +158,18 @@ function AcceptInviteContent() {
|
||||
);
|
||||
}
|
||||
|
||||
function AcceptInviteFallback() {
|
||||
const t = useTranslations('auth');
|
||||
return (
|
||||
<div className="min-h-screen app-web-bg flex items-center justify-center">
|
||||
<p className="text-sm text-text-secondary">{t('loadingInvitation')}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AcceptInvitePage() {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="min-h-screen app-web-bg flex items-center justify-center">
|
||||
<p className="text-sm text-text-secondary">Loading invitation...</p>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Suspense fallback={<AcceptInviteFallback />}>
|
||||
<AcceptInviteContent />
|
||||
</Suspense>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user