PromucFlow_constructor/app/client/src/components/ads/UserProfileImagePicker.tsx
Tanvi Bhakta a0292d432a
feat: import changes batch 2 (#15722)
* Remove treedropdown from ads

* Change Treedropdown imports

* Remove Notification Banner, change imports

* Remove Toggle from ads

* Change toggle imports

* explicitly declare function argument types

* Remove Menu from ads

* Change menu imports

* Remove Spinner from ads

* Change spinner imports

* Remove Radio, import changes

* test: updated flaky test under default meta (#15707)

* updated flaky test

* Updated tests

* updated tests

* updated the tests

* updated tests

* Update constants.ts

* add more typecasting

* Remove ListSegmentHeader, import changes

* Remove TagInputComponent, import changes

* Remove Switch, import changes

* Remove SearchInput, change imports

* Rename TagInputComponent to TagInput

* Remove ProgressiveImage, import changes

* import changes for SearchVariant

* Remove menu divider, import changes

* Remove TableDropdown, import changes

* Remove Switcher

* Remove StatusBar, import changes

* Remove showcase carousel

* Remove RectangularSwitcher, import change

* Add types to TableDropdown's args

* Remove MultiSwitch, import change

* Remove GifPlayerComponent, import change

* Remove DraggableList, import change

* Remove DisplayImageUpload, import change

* Remove DatePickerComponent, import change

* Remove CopyToClipBoard, import change

* Remove ColorSelector, import change

* Remove TabItemBackgroundFill, NumberedStep, ColorPickerComponent

* GifPlayerComponent -> GifPlayer

* change named import

* Remove FormFieldError, change imports

* Update to new version of Tree Dropdown

* Fix issue with ads/index.ts

* Test file fix

* Fix issue with merge?!?!??

* update design system to 1.0.18

* Bump ds version

* bump ds version

* bump ds version

Co-authored-by: NandanAnantharamu <67676905+NandanAnantharamu@users.noreply.github.com>
Co-authored-by: Albin <albin@appsmith.com>
2022-09-02 14:08:17 +05:30

65 lines
1.6 KiB
TypeScript

import React, { useState, useRef, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { updatePhoto, removePhoto, updatePhotoId } from "actions/userActions";
import { getCurrentUser } from "selectors/usersSelectors";
import { USER_PHOTO_ASSET_URL } from "constants/userConstants";
import { DisplayImageUpload } from "design-system";
import Uppy from "@uppy/core";
function FormDisplayImage() {
const [file, setFile] = useState<any>();
const dispatch = useDispatch();
const user = useSelector(getCurrentUser);
const dispatchActionRef = useRef<(uppy: Uppy.Uppy) => void | null>();
const imageURL = user?.photoId
? `/api/${USER_PHOTO_ASSET_URL}/${user?.photoId}`
: "";
const onUploadComplete = (uppy: Uppy.Uppy, photoId: string) => {
uppy.reset();
dispatch(updatePhotoId({ photoId }));
};
const onSelectFile = (file: any) => {
setFile(file.data);
};
useEffect(() => {
dispatchActionRef.current = (uppy: Uppy.Uppy) => {
dispatch(
updatePhoto({
file,
callback: (photoId: string) => onUploadComplete(uppy, photoId),
}),
);
};
}, [file]);
const upload = (uppy: Uppy.Uppy) => {
if (typeof dispatchActionRef.current === "function")
dispatchActionRef.current(uppy);
};
const removeProfileImage = () => {
dispatch(
removePhoto((photoId: string) => {
dispatch(updatePhotoId({ photoId }));
}),
);
};
return (
<DisplayImageUpload
onChange={onSelectFile}
onRemove={removeProfileImage}
submit={upload}
value={imageURL}
/>
);
}
export default FormDisplayImage;