forked from github/plane
fix: profile cover fix (#4010)
This commit is contained in:
parent
0d2a8cca50
commit
8911eaf676
@ -40,13 +40,14 @@ type Props = {
|
|||||||
onChange: (data: string) => void;
|
onChange: (data: string) => void;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
tabIndex?: number;
|
tabIndex?: number;
|
||||||
|
isProfileCover?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
// services
|
// services
|
||||||
const fileService = new FileService();
|
const fileService = new FileService();
|
||||||
|
|
||||||
export const ImagePickerPopover: React.FC<Props> = observer((props) => {
|
export const ImagePickerPopover: React.FC<Props> = observer((props) => {
|
||||||
const { label, value, control, onChange, disabled = false, tabIndex } = props;
|
const { label, value, control, onChange, disabled = false, tabIndex, isProfileCover = false } = props;
|
||||||
// states
|
// states
|
||||||
const [image, setImage] = useState<File | null>(null);
|
const [image, setImage] = useState<File | null>(null);
|
||||||
const [isImageUploading, setIsImageUploading] = useState(false);
|
const [isImageUploading, setIsImageUploading] = useState(false);
|
||||||
@ -97,31 +98,47 @@ export const ImagePickerPopover: React.FC<Props> = observer((props) => {
|
|||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
setIsImageUploading(true);
|
setIsImageUploading(true);
|
||||||
|
|
||||||
if (!image || !workspaceSlug) return;
|
if (!image) return;
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("asset", image);
|
formData.append("asset", image);
|
||||||
formData.append("attributes", JSON.stringify({}));
|
formData.append("attributes", JSON.stringify({}));
|
||||||
|
|
||||||
fileService
|
const oldValue = value;
|
||||||
.uploadFile(workspaceSlug.toString(), formData)
|
const isUnsplashImage = oldValue?.split("/")[2] === "images.unsplash.com";
|
||||||
.then((res) => {
|
|
||||||
const oldValue = value;
|
|
||||||
const isUnsplashImage = oldValue?.split("/")[2] === "images.unsplash.com";
|
|
||||||
|
|
||||||
const imageUrl = res.asset;
|
const uploadCallback = (res: any) => {
|
||||||
onChange(imageUrl);
|
const imageUrl = res.asset;
|
||||||
setIsImageUploading(false);
|
onChange(imageUrl);
|
||||||
setImage(null);
|
setIsImageUploading(false);
|
||||||
setIsOpen(false);
|
setImage(null);
|
||||||
|
setIsOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
if (isUnsplashImage) return;
|
if (isProfileCover) {
|
||||||
|
fileService
|
||||||
if (oldValue && currentWorkspace) fileService.deleteFile(currentWorkspace.id, oldValue);
|
.uploadUserFile(formData)
|
||||||
})
|
.then((res) => {
|
||||||
.catch((err) => {
|
uploadCallback(res);
|
||||||
console.error(err);
|
if (isUnsplashImage) return;
|
||||||
});
|
if (oldValue && currentWorkspace) fileService.deleteUserFile(oldValue);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (!workspaceSlug) return;
|
||||||
|
fileService
|
||||||
|
.uploadFile(workspaceSlug.toString(), formData)
|
||||||
|
.then((res) => {
|
||||||
|
uploadCallback(res);
|
||||||
|
if (isUnsplashImage) return;
|
||||||
|
if (oldValue && currentWorkspace) fileService.deleteFile(currentWorkspace.id, oldValue);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -215,6 +215,7 @@ const ProfileSettingsPage: NextPageWithLayout = observer(() => {
|
|||||||
onChange={(imageUrl) => onChange(imageUrl)}
|
onChange={(imageUrl) => onChange(imageUrl)}
|
||||||
control={control}
|
control={control}
|
||||||
value={value ?? "https://images.unsplash.com/photo-1506383796573-caf02b4a79ab"}
|
value={value ?? "https://images.unsplash.com/photo-1506383796573-caf02b4a79ab"}
|
||||||
|
isProfileCover
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user