From 54f69f7c36cf8e8f9f9081865135cd73e4386ba0 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Wed, 1 Oct 2025 16:52:23 +0300 Subject: [PATCH] Refactor UpdateProfile component to use useClientOnce for initial profile update - Replaced useEffect with useClientOnce to handle the first login profile update more efficiently. - Removed local state management for hasUpdated, simplifying the component logic. - Updated localStorage handling to ensure the profile update occurs only on the first login. --- apps/web/components/auth/update-profile.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/web/components/auth/update-profile.tsx b/apps/web/components/auth/update-profile.tsx index be66aef..139e72c 100644 --- a/apps/web/components/auth/update-profile.tsx +++ b/apps/web/components/auth/update-profile.tsx @@ -1,25 +1,27 @@ 'use client'; import { useCustomerMutation } from '@/hooks/api/customers'; +import { useClientOnce } from '@/hooks/telegram'; import { initData, useSignal } from '@telegram-apps/sdk-react'; -import { useEffect, useState } from 'react'; export function UpdateProfile() { const initDataUser = useSignal(initData.user); const { mutate: updateProfile } = useCustomerMutation(); - const [hasUpdated, setHasUpdated] = useState(false); - useEffect(() => { - if (!hasUpdated) { + useClientOnce(() => { + if ( + localStorage.getItem('firstLogin') === null || + localStorage.getItem('firstLogin') === 'true' + ) { updateProfile({ data: { active: true, photoUrl: initDataUser?.photoUrl || undefined, }, }); - setHasUpdated(true); + localStorage.setItem('firstLogin', 'false'); } - }, [hasUpdated, initDataUser?.photoUrl, updateProfile]); + }); return null; }