mirror of
https://github.com/docmost/docmost.git
synced 2025-11-23 17:31:11 +10:00
fix profile image
This commit is contained in:
@ -13,23 +13,18 @@ export default function AccountAvatar() {
|
||||
const [currentUser] = useAtom(currentUserAtom);
|
||||
const [, setUser] = useAtom(userAtom);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
||||
|
||||
const handleFileChange = async (selectedFile: File) => {
|
||||
if (!selectedFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (previewUrl) {
|
||||
URL.revokeObjectURL(previewUrl);
|
||||
}
|
||||
|
||||
setFile(selectedFile);
|
||||
setPreviewUrl(URL.createObjectURL(selectedFile));
|
||||
|
||||
try {
|
||||
setIsLoading(true);
|
||||
await uploadAvatar(selectedFile);
|
||||
const avatar = await uploadAvatar(selectedFile);
|
||||
|
||||
setUser((prev) => ({ ...prev, avatarUrl: avatar.fileName }));
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
} finally {
|
||||
@ -37,6 +32,8 @@ export default function AccountAvatar() {
|
||||
}
|
||||
};
|
||||
|
||||
console.log(currentUser?.user.avatarUrl);
|
||||
|
||||
return (
|
||||
<>
|
||||
<FileButton onChange={handleFileChange} accept="image/png,image/jpeg">
|
||||
@ -47,8 +44,8 @@ export default function AccountAvatar() {
|
||||
component="button"
|
||||
radius="xl"
|
||||
size="60px"
|
||||
avatarUrl={previewUrl || currentUser.user.avatarUrl}
|
||||
name={currentUser.user.name}
|
||||
avatarUrl={currentUser?.user.avatarUrl}
|
||||
name={currentUser?.user.name}
|
||||
style={{ cursor: "pointer" }}
|
||||
/>
|
||||
</Tooltip>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import api from "@/lib/api-client";
|
||||
import { ICurrentUser, IUser } from "@/features/user/types/user.types";
|
||||
import { IAttachment } from "@/lib/types.ts";
|
||||
|
||||
export async function getMyInfo(): Promise<ICurrentUser> {
|
||||
const req = await api.post<ICurrentUser>("/users/me");
|
||||
@ -11,7 +12,7 @@ export async function updateUser(data: Partial<IUser>): Promise<IUser> {
|
||||
return req.data as IUser;
|
||||
}
|
||||
|
||||
export async function uploadAvatar(file: File) {
|
||||
export async function uploadAvatar(file: File): Promise<any> {
|
||||
const formData = new FormData();
|
||||
formData.append("type", "avatar");
|
||||
formData.append("image", file);
|
||||
@ -21,5 +22,6 @@ export async function uploadAvatar(file: File) {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
});
|
||||
return req.data;
|
||||
console.log(req);
|
||||
return req;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user