feat: added mutation and function to platform for updating user profile name (#3929)

Co-authored-by: amk-dev <akash.k.mohan98@gmail.com>
Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
This commit is contained in:
Nivedin
2024-03-25 14:41:25 +05:30
committed by GitHub
parent 1113c79e20
commit c326f54f7e
7 changed files with 68 additions and 18 deletions

View File

@@ -210,6 +210,8 @@ import { toggleSetting } from "~/newstore/settings"
import IconVerified from "~icons/lucide/verified"
import IconSettings from "~icons/lucide/settings"
import * as E from "fp-ts/Either"
type ProfileTabs = "sync" | "teams"
const selectedProfileTab = ref<ProfileTabs>("sync")
@@ -244,19 +246,28 @@ const displayName = ref(currentUser.value?.displayName || "")
const updatingDisplayName = ref(false)
watchEffect(() => (displayName.value = currentUser.value?.displayName || ""))
const updateDisplayName = () => {
const updateDisplayName = async () => {
if (!displayName.value) {
toast.error(`${t("error.empty_profile_name")}`)
return
}
if (currentUser.value?.displayName === displayName.value) {
toast.error(`${t("error.same_profile_name")}`)
return
}
updatingDisplayName.value = true
platform.auth
.setDisplayName(displayName.value as string)
.then(() => {
toast.success(`${t("profile.updated")}`)
})
.catch(() => {
toast.error(`${t("error.something_went_wrong")}`)
})
.finally(() => {
updatingDisplayName.value = false
})
const res = await platform.auth.setDisplayName(displayName.value)
if (E.isLeft(res)) {
toast.error(t("error.something_went_wrong"))
} else if (E.isRight(res)) {
toast.success(`${t("profile.updated")}`)
}
updatingDisplayName.value = false
}
const emailAddress = ref(currentUser.value?.email || "")