import useFollowStatus from '@/hooks/data-fetching/user-follows/useFollowStatus'; import useGetUsersFollowedByUser from '@/hooks/data-fetching/user-follows/useGetUsersFollowedByUser'; import useGetUsersFollowingUser from '@/hooks/data-fetching/user-follows/useGetUsersFollowingUser'; import { sendUserFollowRequest } from '@/requests/users/auth'; import GetUserSchema from '@/services/users/auth/schema/GetUserSchema'; import { FC, useState } from 'react'; import { FaUserCheck, FaUserPlus } from 'react-icons/fa'; import { z } from 'zod'; interface UserFollowButtonProps { mutateFollowerCount: ReturnType['mutate']; mutateFollowingCount: ReturnType['mutate']; user: z.infer; } const UserFollowButton: FC = ({ user, mutateFollowerCount, mutateFollowingCount, }) => { const { isFollowed, mutate: mutateFollowStatus } = useFollowStatus(user.id); const [isLoading, setIsLoading] = useState(false); const onClick = async () => { try { setIsLoading(true); await sendUserFollowRequest({ userId: user.id }); await Promise.all([ mutateFollowStatus(), mutateFollowerCount(), mutateFollowingCount(), ]); setIsLoading(false); } catch (e) { setIsLoading(false); } }; return ( ); }; export default UserFollowButton;