Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 9x 1894x 1894x 1894x 1894x 1894x 1894x 1894x | import { addSizeToImage } from "@components/UploadAvatar/UploadAvatar";
import { useUploadImageToS3 } from "@hooks/upload-api/uploadHooks";
import { updatePartialUser } from "@redux/slices/auth/auth";
import { useGetUser } from "@services/api/onboarding/user";
import { updateUser } from "@services/api/upload/uploadEndpoints";
import { useMutation, useQueryClient } from "react-query";
import { useDispatch } from "react-redux";
export const useChangeProfileAvatar = () => {
const { mutateAsync } = useUploadImageToS3();
const { data: userData } = useGetUser();
const queryClient = useQueryClient();
const dispatch = useDispatch();
const handleChangeStatus = async ({ file }: { file: File }) => {
const responses = await mutateAsync({
file: file,
formType: "customer_avatar",
});
const url = responses ? responses.response.URL : null;
updateUserImage(url);
};
const updateUserData = useMutation((data: any) => {
return updateUser({
accID: userData.accID,
data,
});
});
function updateUserImage(url: string | null) {
const imageURL = { imageURL: url };
updateUserData.mutate(imageURL, {
onSuccess: (res: any) => {
const user = queryClient.getQueryData("user");
if (user) {
queryClient.setQueryData(
"user",
Object.assign(user as object, imageURL),
);
}
dispatch(
updatePartialUser({
img: addSizeToImage(url || "", "thumb"),
}),
);
},
});
}
return {
handleChangeStatus,
updateUserImage,
};
};
|