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.
This commit is contained in:
parent
8cb283d4ba
commit
54f69f7c36
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user