- 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.
28 lines
701 B
TypeScript
28 lines
701 B
TypeScript
'use client';
|
|
|
|
import { useCustomerMutation } from '@/hooks/api/customers';
|
|
import { useClientOnce } from '@/hooks/telegram';
|
|
import { initData, useSignal } from '@telegram-apps/sdk-react';
|
|
|
|
export function UpdateProfile() {
|
|
const initDataUser = useSignal(initData.user);
|
|
const { mutate: updateProfile } = useCustomerMutation();
|
|
|
|
useClientOnce(() => {
|
|
if (
|
|
localStorage.getItem('firstLogin') === null ||
|
|
localStorage.getItem('firstLogin') === 'true'
|
|
) {
|
|
updateProfile({
|
|
data: {
|
|
active: true,
|
|
photoUrl: initDataUser?.photoUrl || undefined,
|
|
},
|
|
});
|
|
localStorage.setItem('firstLogin', 'false');
|
|
}
|
|
});
|
|
|
|
return null;
|
|
}
|