add user consent url

This commit is contained in:
Danel Kungla
2025-09-12 18:34:45 +03:00
parent 781a21aef4
commit 74edc6c679
4 changed files with 35 additions and 19 deletions

View File

@@ -1,13 +1,14 @@
'use client'; 'use client';
import Link from 'next/link'; import Link from 'next/link';
import { useTranslation } from 'react-i18next';
import { useRouter } from 'next/navigation'; import { useRouter } from 'next/navigation';
import { z } from 'zod';
import { pathsConfig } from '@/packages/shared/src/config';
import { ExternalLink } from '@/public/assets/external-link'; import { ExternalLink } from '@/public/assets/external-link';
import { zodResolver } from '@hookform/resolvers/zod'; import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { z } from 'zod';
import { Button } from '@kit/ui/button'; import { Button } from '@kit/ui/button';
import { Checkbox } from '@kit/ui/checkbox'; import { Checkbox } from '@kit/ui/checkbox';
@@ -20,21 +21,22 @@ import {
FormMessage, FormMessage,
} from '@kit/ui/form'; } from '@kit/ui/form';
import { Input } from '@kit/ui/input'; import { Input } from '@kit/ui/input';
import { toast } from '@kit/ui/sonner';
import { Trans } from '@kit/ui/trans'; import { Trans } from '@kit/ui/trans';
import { UpdateAccountSchemaClient } from '../_lib/schemas/update-account.schema'; import { UpdateAccountSchemaClient } from '../_lib/schemas/update-account.schema';
import { onUpdateAccount } from '../_lib/server/update-account'; import { onUpdateAccount } from '../_lib/server/update-account';
import { toast } from '@kit/ui/sonner';
import { pathsConfig } from '@/packages/shared/src/config';
type UpdateAccountFormValues = z.infer<ReturnType<typeof UpdateAccountSchemaClient>>; type UpdateAccountFormValues = z.infer<
ReturnType<typeof UpdateAccountSchemaClient>
>;
export function UpdateAccountForm({ export function UpdateAccountForm({
defaultValues, defaultValues,
isEmailUser, isEmailUser,
}: { }: {
defaultValues: UpdateAccountFormValues, defaultValues: UpdateAccountFormValues;
isEmailUser: boolean, isEmailUser: boolean;
}) { }) {
const router = useRouter(); const router = useRouter();
const { t } = useTranslation('account'); const { t } = useTranslation('account');
@@ -45,10 +47,13 @@ export function UpdateAccountForm({
defaultValues, defaultValues,
}); });
const { firstName, lastName, personalCode, email, userConsent } = defaultValues; const { firstName, lastName, personalCode, email, userConsent } =
defaultValues;
const defaultValues_weight = "weight" in defaultValues ? defaultValues.weight : null; const defaultValues_weight =
const defaultValues_height = "height" in defaultValues ? defaultValues.height : null; 'weight' in defaultValues ? defaultValues.weight : null;
const defaultValues_height =
'height' in defaultValues ? defaultValues.height : null;
const hasFirstName = !!firstName; const hasFirstName = !!firstName;
const hasLastName = !!lastName; const hasLastName = !!lastName;
@@ -64,8 +69,12 @@ export function UpdateAccountForm({
personalCode: values.personalCode || personalCode, personalCode: values.personalCode || personalCode,
email: values.email || email, email: values.email || email,
phone: values.phone, phone: values.phone,
weight: ((("weight" in values && values.weight) ?? defaultValues_weight) || null) as number, weight: ((('weight' in values && values.weight) ??
height: ((("height" in values && values.height) ?? defaultValues_height) || null) as number, defaultValues_weight) ||
null) as number,
height: ((('height' in values && values.height) ??
defaultValues_height) ||
null) as number,
userConsent: values.userConsent ?? userConsent, userConsent: values.userConsent ?? userConsent,
city: values.city, city: values.city,
}); });
@@ -81,7 +90,7 @@ export function UpdateAccountForm({
router.push(pathsConfig.app.selectPackage); router.push(pathsConfig.app.selectPackage);
} }
} catch (error) { } catch (error) {
console.info("promiseresult error", error); console.info('promiseresult error', error);
toast.error(t('updateAccount.updateAccountError')); toast.error(t('updateAccount.updateAccountError'));
toast.dismiss(loading); toast.dismiss(loading);
} }
@@ -205,7 +214,9 @@ export function UpdateAccountForm({
value={field.value ?? ''} value={field.value ?? ''}
onChange={(e) => onChange={(e) =>
field.onChange( field.onChange(
e.target.value === '' ? null : Number(e.target.value), e.target.value === ''
? null
: Number(e.target.value),
) )
} }
/> />
@@ -230,7 +241,9 @@ export function UpdateAccountForm({
value={field.value ?? ''} value={field.value ?? ''}
onChange={(e) => onChange={(e) =>
field.onChange( field.onChange(
e.target.value === '' ? null : Number(e.target.value), e.target.value === ''
? null
: Number(e.target.value),
) )
} }
/> />
@@ -260,7 +273,7 @@ export function UpdateAccountForm({
</div> </div>
<Link <Link
href={''} href={t('account:updateAccount:userConsentUrlPath')}
className="flex flex-row items-center gap-2 text-sm hover:underline" className="flex flex-row items-center gap-2 text-sm hover:underline"
target="_blank" target="_blank"
> >

View File

@@ -131,6 +131,7 @@
"button": "Continue", "button": "Continue",
"userConsentLabel": "I agree to the use of personal data on the platform", "userConsentLabel": "I agree to the use of personal data on the platform",
"userConsentUrlTitle": "View privacy policy", "userConsentUrlTitle": "View privacy policy",
"userConsentUrlPath": "https://medreport.ee/privaatsustingimused/",
"updateAccountLoading": "Updating account details...", "updateAccountLoading": "Updating account details...",
"updateAccountSuccess": "Account details updated", "updateAccountSuccess": "Account details updated",
"updateAccountError": "Updating account details error" "updateAccountError": "Updating account details error"
@@ -169,4 +170,4 @@
"updateAccountPreferencesSuccess": "Account preferences updated", "updateAccountPreferencesSuccess": "Account preferences updated",
"updateAccountPreferencesError": "Updating account preferences failed", "updateAccountPreferencesError": "Updating account preferences failed",
"consents": "Consents" "consents": "Consents"
} }

View File

@@ -131,6 +131,7 @@
"button": "Jätka", "button": "Jätka",
"userConsentLabel": "Nõustun isikuandmete kasutamisega platvormil", "userConsentLabel": "Nõustun isikuandmete kasutamisega platvormil",
"userConsentUrlTitle": "Vaata isikuandmete töötlemise põhimõtteid", "userConsentUrlTitle": "Vaata isikuandmete töötlemise põhimõtteid",
"userConsentUrlPath": "https://medreport.ee/privaatsustingimused/",
"updateAccountLoading": "Konto andmed uuendatakse...", "updateAccountLoading": "Konto andmed uuendatakse...",
"updateAccountSuccess": "Konto andmed uuendatud", "updateAccountSuccess": "Konto andmed uuendatud",
"updateAccountError": "Konto andmete uuendamine ebaõnnestus" "updateAccountError": "Konto andmete uuendamine ebaõnnestus"
@@ -169,4 +170,4 @@
"updateAccountPreferencesSuccess": "Konto eelistused uuendatud", "updateAccountPreferencesSuccess": "Konto eelistused uuendatud",
"updateAccountPreferencesError": "Konto eelistused uuendamine ebaõnnestus", "updateAccountPreferencesError": "Konto eelistused uuendamine ebaõnnestus",
"consents": "Nõusolekud" "consents": "Nõusolekud"
} }

View File

@@ -131,6 +131,7 @@
"button": "Продолжить", "button": "Продолжить",
"userConsentLabel": "Я согласен на использование персональных данных на платформе", "userConsentLabel": "Я согласен на использование персональных данных на платформе",
"userConsentUrlTitle": "Посмотреть политику конфиденциальности", "userConsentUrlTitle": "Посмотреть политику конфиденциальности",
"userConsentUrlPath": "https://medreport.ee/privaatsustingimused/",
"updateAccountLoading": "Обновление данных аккаунта...", "updateAccountLoading": "Обновление данных аккаунта...",
"updateAccountSuccess": "Данные аккаунта обновлены", "updateAccountSuccess": "Данные аккаунта обновлены",
"updateAccountError": "Не удалось обновить данные аккаунта" "updateAccountError": "Не удалось обновить данные аккаунта"
@@ -169,4 +170,4 @@
"updateAccountPreferencesSuccess": "Предпочтения аккаунта обновлены", "updateAccountPreferencesSuccess": "Предпочтения аккаунта обновлены",
"updateAccountPreferencesError": "Не удалось обновить предпочтения аккаунта", "updateAccountPreferencesError": "Не удалось обновить предпочтения аккаунта",
"consents": "Согласия" "consents": "Согласия"
} }