update user

This commit is contained in:
Zamitto 2024-06-18 12:10:36 -03:00
parent 59b2096d06
commit e467bbff66
2 changed files with 17 additions and 6 deletions

View File

@ -22,7 +22,8 @@ export interface ProfileContentProps {
export function UserContent({ userProfile }: ProfileContentProps) {
const { t, i18n } = useTranslation("user_profile");
const { userDetails, profileBackground, signOut } = useUserDetails();
const { userDetails, profileBackground, signOut, updateUser } =
useUserDetails();
const [showEditProfileModal, setShowEditProfileModal] = useState(false);
@ -79,6 +80,7 @@ export function UserContent({ userProfile }: ProfileContentProps) {
<UserEditProfileModal
visible={showEditProfileModal}
onClose={() => setShowEditProfileModal(false)}
updateUser={updateUser}
userProfile={userProfile}
/>

View File

@ -4,22 +4,27 @@ import * as styles from "./user.css";
import { PersonIcon } from "@primer/octicons-react";
import { SPACING_UNIT } from "@renderer/theme.css";
import { useState } from "react";
import { useToast } from "@renderer/hooks";
export interface UserEditProfileModalProps {
userProfile: UserProfile;
visible: boolean;
onClose: () => void;
updateUser: () => Promise<void>;
}
export const UserEditProfileModal = ({
userProfile,
visible,
onClose,
updateUser,
}: UserEditProfileModalProps) => {
const [displayName, setDisplayName] = useState(userProfile.displayName);
const [newImagePath, setNewImagePath] = useState<string | null>(null);
const [newImageBase64, setNewImageBase64] = useState<string | null>(null);
const { showSuccessToast, showErrorToast } = useToast();
const handleChangeProfileAvatar = async () => {
const { filePaths } = await window.electron.showOpenDialog({
properties: ["openFile"],
@ -43,13 +48,17 @@ export const UserEditProfileModal = ({
};
const handleSaveProfile = async () => {
await window.electron
window.electron
.updateProfile(displayName, newImagePath)
.catch((err) => {
console.log("errro", err);
.then(() => {
updateUser();
setNewImagePath(null);
showSuccessToast("Sucesso");
onClose();
})
.catch(() => {
showErrorToast("Erro");
});
setNewImagePath(null);
onClose();
};
return (
<>