Skip to content

Implement modal for user name and profile picture update#2

Merged
andrejsshell merged 2 commits intomainfrom
feature/issue#1-az
Sep 29, 2022
Merged

Implement modal for user name and profile picture update#2
andrejsshell merged 2 commits intomainfrom
feature/issue#1-az

Conversation

@Zografska
Copy link
Copy Markdown
Collaborator

Implement logic for issue#1

}, [asPath]);

useEffect(() => {
console.log(user);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this console.log

Comment on lines +13 to +35
const [uploadedPicture, setUploadedPicture] = useState<File>(null);
const { user, showOnboardingModal, setUser } = useUser();
const { mutateAsync, isLoading, error, isError } = useMutation(
['/update-user'],
async (formData : FormData) => fetcher.put(`/users/${user.id}`, formData, { headers: { 'Content-Type': 'multipart/form-data' } }),
{ onSuccess: (data: UserUpdatedResponse) => {
const { data: { firstName, lastName, profilePicture } } = data;
if (data.data.profilePicture){
setUser({ ...user, firstName, lastName, profilePicture });
} else {
setUser({ ...user, firstName, lastName });
}
} },
);
const onDrop = useCallback((acceptedFile) => {
setUploadedPicture(acceptedFile[0]);
}, []);
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop,
maxFiles: 1,
accept: {
'image/jpeg': [],
'image/png': [],
} });
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformat this code a little so it's more readable.

Suggested change
const [uploadedPicture, setUploadedPicture] = useState<File>(null);
const { user, showOnboardingModal, setUser } = useUser();
const { mutateAsync, isLoading, error, isError } = useMutation(
['/update-user'],
async (formData : FormData) => fetcher.put(`/users/${user.id}`, formData, { headers: { 'Content-Type': 'multipart/form-data' } }),
{ onSuccess: (data: UserUpdatedResponse) => {
const { data: { firstName, lastName, profilePicture } } = data;
if (data.data.profilePicture){
setUser({ ...user, firstName, lastName, profilePicture });
} else {
setUser({ ...user, firstName, lastName });
}
} },
);
const onDrop = useCallback((acceptedFile) => {
setUploadedPicture(acceptedFile[0]);
}, []);
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop,
maxFiles: 1,
accept: {
'image/jpeg': [],
'image/png': [],
} });
const [uploadedPicture, setUploadedPicture] = useState<File>(null);
const { user, showOnboardingModal, setUser } = useUser();
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop,
maxFiles: 1,
accept: {
'image/jpeg': [],
'image/png': [],
} });
const onDrop = useCallback((acceptedFile) => {
setUploadedPicture(acceptedFile[0]);
}, []);
const { mutateAsync, isLoading, error, isError } = useMutation(
['/update-user'],
async (formData : FormData) => fetcher.put(`/users/${user.id}`, formData, { headers: { 'Content-Type': 'multipart/form-data' } }),
{ onSuccess: (data: UserUpdatedResponse) => {
const { data: { firstName, lastName, profilePicture } } = data;
if (data.data.profilePicture){
setUser({ ...user, firstName, lastName, profilePicture });
} else {
setUser({ ...user, firstName, lastName });
}
} },
);

Comment on lines +42 to +43
<ModalHeader>Modal Title</ModalHeader>
<ModalCloseButton />
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the header and the close button.

@andrejsshell andrejsshell merged commit 7f3a2f2 into main Sep 29, 2022
@andrejsshell andrejsshell deleted the feature/issue#1-az branch September 29, 2022 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants