Skip to content

Instantly share code, notes, and snippets.

@mrhat24
Created August 31, 2022 12:19
Show Gist options
  • Select an option

  • Save mrhat24/b5d7c789da9fe59a48b9187f9d180747 to your computer and use it in GitHub Desktop.

Select an option

Save mrhat24/b5d7c789da9fe59a48b9187f9d180747 to your computer and use it in GitHub Desktop.
import { FC, useEffect } from 'react';
import { View } from './view';
import { useDispatch } from 'react-redux';
// import { profileAvatarSelector } from 'redux/selectors';
// import { getProfileAvatar, updateProfileAvatar } from 'redux/actions';
import { AppDispatch } from 'redux/store';
import { usersApi } from 'api/users/usersApi';
const userId = '610635d0-d5af-422a-a1c2-f88a35495b65';
export const Settings: FC = () => {
const {
useUserControllerGetUserQuery,
useAvatarControllerUploadAvatarMutation
} = usersApi;
const dispatch = useDispatch<AppDispatch>();
const { data: datauser, isLoading: isLoadinguser, isSuccess,
isError } = useUserControllerGetUserQuery({ userId: userId });
// console.log('datauser', datauser);
// const { data: dataAvatar, isLoading: isLoadingAvatar, isSuccess: isSuccessAvatar,
// isError: isErrorAvatar } = useAvatarControllerGetAvatarQuery({ id: '1' });
// console.log('data', dataAvatar);
// console.log('isSuccess', isSuccessAvatar);
// console.log('isError', isErrorAvatar);
const [updateAvatar,
{
data: updatedAvatarData,
isLoading: isLoadingUpdateAvatar,
isSuccess: isSuccessUpdateAvatar,
isError: isErrorUpdateAvatar
}] = useAvatarControllerUploadAvatarMutation();
const avatar = `${process.env.REACT_APP_BACKEND_URL}/api/users/${userId}/avatar`;
useEffect(() => {
// dispatch(getProfileAvatar(userId));
}, [dispatch, userId]);
const onAvatarUpload = (file: File) => {
const data = new FormData() as any;
data.append('file', file, file?.name);
updateAvatar({ id: '1', body: data }).unwrap();
// dispatch(updateProfileAvatar({ id: userId, data }));
};
return View({
avatar,
handleAvatarUpload: onAvatarUpload,
isAvatarLoading: false,
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment