fix and update
This commit is contained in:
@@ -44,6 +44,7 @@ export function AddressQuickSection({
|
||||
isReady?: boolean;
|
||||
}) {
|
||||
const { user, token } = useAuth();
|
||||
const userId = user?.id;
|
||||
const { showToast } = useToast();
|
||||
const [addresses, setAddresses] = useState<UserAddress[]>([]);
|
||||
const [formOpen, setFormOpen] = useState(false);
|
||||
@@ -51,19 +52,19 @@ export function AddressQuickSection({
|
||||
const [editingAddress, setEditingAddress] = useState<UserAddress | null>(null);
|
||||
|
||||
const loadAddresses = useCallback(async () => {
|
||||
if (!user || !token || isPinLocked || !isReady) return;
|
||||
if (!userId || !token || isPinLocked || !isReady) return;
|
||||
try {
|
||||
const response = await fetchUserAddresses(user.id, token);
|
||||
const response = await fetchUserAddresses(userId, token);
|
||||
setAddresses(response.addresses ?? []);
|
||||
} catch (error) {
|
||||
const message = getApiErrorMessage(error, 'Не удалось загрузить адреса');
|
||||
if (message) showToast(message);
|
||||
}
|
||||
}, [isPinLocked, isReady, showToast, token, user]);
|
||||
}, [isPinLocked, isReady, showToast, token, userId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isReady && user && !isPinLocked) void loadAddresses();
|
||||
}, [isPinLocked, isReady, loadAddresses, user]);
|
||||
if (isReady && userId && !isPinLocked) void loadAddresses();
|
||||
}, [isPinLocked, isReady, loadAddresses, userId]);
|
||||
|
||||
const homeAddress = useMemo(() => getPrimaryAddress(addresses, 'HOME') as UserAddress | null, [addresses]);
|
||||
const workAddress = useMemo(() => getPrimaryAddress(addresses, 'WORK') as UserAddress | null, [addresses]);
|
||||
|
||||
Reference in New Issue
Block a user