diff --git a/packages/vue-ui/src/Data/Index.vue b/packages/vue-ui/src/Data/Index.vue index baa64743e..36f6e7024 100644 --- a/packages/vue-ui/src/Data/Index.vue +++ b/packages/vue-ui/src/Data/Index.vue @@ -38,8 +38,8 @@ const props = defineProps({ required: true, }, value: { + default: "", type: [Object, String, Number] as PropType, - required: true, }, }); diff --git a/packages/vue-user/src/components/AuthGoogleCallback.vue b/packages/vue-user/src/components/AuthGoogleCallback.vue index eecefe33f..ff3f35975 100644 --- a/packages/vue-user/src/components/AuthGoogleCallback.vue +++ b/packages/vue-user/src/components/AuthGoogleCallback.vue @@ -19,6 +19,7 @@ import { useTranslations } from "../index"; import useUserStore from "../store"; import { verifySessionRoles } from "../supertokens"; +import type { UserType } from "../types"; import type { AppConfig } from "@dzangolab/vue3-config"; const config = useConfig() as AppConfig; @@ -48,7 +49,7 @@ onMounted(async () => { (supportedRoles && (await verifySessionRoles(supportedRoles))) || !supportedRoles?.length ) { - setUser(response.user); + setUser(response.user as UserType); router.push({ name: "home" }); } diff --git a/packages/vue-user/src/components/index.ts b/packages/vue-user/src/components/index.ts index 9fc3e12ba..71f57abc7 100644 --- a/packages/vue-user/src/components/index.ts +++ b/packages/vue-user/src/components/index.ts @@ -1,3 +1,4 @@ +export { default as AccountInfo } from "./profile/AccountInfo.vue"; export { default as ChangePasswordForm } from "./ChangePasswordForm.vue"; export { default as DropdownUserMenu } from "./DropdownUserMenu.vue"; export { default as InvitationForm } from "./invitation/InvitationForm.vue"; @@ -9,4 +10,5 @@ export { default as SignInUpMenu } from "./SignInUpMenu.vue"; export { default as SignupForm } from "./SignupForm.vue"; export { default as TermsAndConditions } from "./TermsAndConditions.vue"; export { default as UpdateEmailForm } from "./profile/UpdateEmailForm.vue"; +export { default as UpdateEmailModal } from "./profile/UpdateEmailModal.vue"; export { default as UserMenu } from "./UserMenu.vue"; diff --git a/packages/vue-user/src/components/profile/AccountInfo.vue b/packages/vue-user/src/components/profile/AccountInfo.vue new file mode 100644 index 000000000..69562eb85 --- /dev/null +++ b/packages/vue-user/src/components/profile/AccountInfo.vue @@ -0,0 +1,82 @@ + + + + + + + diff --git a/packages/vue-user/src/components/profile/UpdateEmailForm.vue b/packages/vue-user/src/components/profile/UpdateEmailForm.vue index 3f30578d1..744540ea7 100644 --- a/packages/vue-user/src/components/profile/UpdateEmailForm.vue +++ b/packages/vue-user/src/components/profile/UpdateEmailForm.vue @@ -36,6 +36,8 @@ type UpdateEmailFormData = { email: string; }; +const emit = defineEmits(["email:updateProcessed"]); + const config = useConfig(); const messages = useTranslations(); @@ -81,6 +83,8 @@ const onSubmit = async (data: UpdateEmailFormData) => { }); } + emit("email:updateProcessed"); + dzangolabVueUpdateEmail.value?.resetForm(); break; } case "EMAIL_ALREADY_EXISTS_ERROR": { @@ -120,7 +124,6 @@ const onSubmit = async (data: UpdateEmailFormData) => { } } - dzangolabVueUpdateEmail.value?.resetForm(); loading.value = false; } catch (error) { emitter.emit("notify", { diff --git a/packages/vue-user/src/components/profile/UpdateEmailModal.vue b/packages/vue-user/src/components/profile/UpdateEmailModal.vue new file mode 100644 index 000000000..883db6b72 --- /dev/null +++ b/packages/vue-user/src/components/profile/UpdateEmailModal.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/packages/vue-user/src/locales/messages.json b/packages/vue-user/src/locales/messages.json index da3dafc4b..9570964dd 100644 --- a/packages/vue-user/src/locales/messages.json +++ b/packages/vue-user/src/locales/messages.json @@ -147,6 +147,9 @@ }, "profile": { "accountInfo": { + "actions": { + "update": "Update" + }, "label": "Email", "newEmail": "New Email", "messages": { @@ -159,7 +162,8 @@ "invalid": "Invalid email", "success": "Email updated successfully.", "verify": "Verify email to complete the email update." - } + }, + "title": "Update email" }, "title": "Profile" }, @@ -351,6 +355,9 @@ }, "profile": { "accountInfo": { + "actions": { + "update": "Update" + }, "label": "Email", "newEmail": "New Email", "messages": { @@ -363,7 +370,8 @@ "invalid": "Invalid email", "success": "Email updated successfully.", "verify": "Verify email to complete the email update." - } + }, + "title": "Update email" }, "title": "Profil" }, diff --git a/packages/vue-user/src/store.ts b/packages/vue-user/src/store.ts index 7e633aacd..5a017bd57 100644 --- a/packages/vue-user/src/store.ts +++ b/packages/vue-user/src/store.ts @@ -16,13 +16,13 @@ import type { PasswordResetPayload, PasswordResetRequestPayload, UpdatePasswordPayload, - User, + UserType, } from "./types"; const USER_KEY = "user"; const useUserStore = defineStore("user", () => { - const user = ref(undefined); + const user = ref(undefined); const changePassword = async ( payload: UpdatePasswordPayload, @@ -33,7 +33,7 @@ const useUserStore = defineStore("user", () => { return response; }; - const getUser = (): User => { + const getUser = (): UserType => { if (user.value) { return user.value; } @@ -81,7 +81,7 @@ const useUserStore = defineStore("user", () => { return doResetPassword(payload); }; - const setUser = (userData: User | undefined) => { + const setUser = (userData: UserType | undefined) => { user.value = userData; localStorage.setItem(USER_KEY, JSON.stringify(userData)); diff --git a/packages/vue-user/src/supertokens/index.ts b/packages/vue-user/src/supertokens/index.ts index c0a1bd3f2..b2d6100cf 100644 --- a/packages/vue-user/src/supertokens/index.ts +++ b/packages/vue-user/src/supertokens/index.ts @@ -17,7 +17,7 @@ import { SUPERTOKENS_API_BASE_PATH_DEFAULT } from "../constant"; import useUserStore from "../store"; import verifyEmail, { getVerificationStatus } from "./verify-email"; -import type { User } from "../types"; +import type { UserType } from "../types"; import type { AppConfig } from "@dzangolab/vue3-config"; const initSupertokens = (config: AppConfig) => { @@ -47,7 +47,7 @@ const isLoggedIn = async () => { return await Session.doesSessionExist(); }; -const getUser = async (): Promise => { +const getUser = async (): Promise => { const { getUser } = useUserStore(); if (await isLoggedIn()) { diff --git a/packages/vue-user/src/supertokens/login.ts b/packages/vue-user/src/supertokens/login.ts index 4c7daee70..7bff1f9f3 100644 --- a/packages/vue-user/src/supertokens/login.ts +++ b/packages/vue-user/src/supertokens/login.ts @@ -1,11 +1,11 @@ import { emailPasswordSignIn } from "supertokens-web-js/recipe/thirdpartyemailpassword"; -import type { LoginCredentials, User } from "../types"; +import type { LoginCredentials, UserType } from "../types"; const login = async ( credentials: LoginCredentials, -): Promise => { - let user: User | undefined; +): Promise => { + let user: UserType | undefined; let response; const data = { @@ -29,7 +29,7 @@ const login = async ( } if (response.status === "OK") { - user = response.user; + user = response.user as UserType; return user; } else if (response.status === "WRONG_CREDENTIALS_ERROR") { diff --git a/packages/vue-user/src/supertokens/signup.ts b/packages/vue-user/src/supertokens/signup.ts index e25c0eb7f..90698787d 100644 --- a/packages/vue-user/src/supertokens/signup.ts +++ b/packages/vue-user/src/supertokens/signup.ts @@ -1,11 +1,11 @@ import { emailPasswordSignUp } from "supertokens-web-js/recipe/thirdpartyemailpassword"; -import type { LoginCredentials, User } from "../types"; +import type { LoginCredentials, UserType } from "../types"; const signup = async ( credentials: LoginCredentials, -): Promise => { - let user: User | undefined; +): Promise => { + let user: UserType | undefined; let response; const data = { @@ -29,7 +29,7 @@ const signup = async ( } if (response.status === "OK") { - user = response.user; + user = response.user as UserType; return user; } else if (response.status === "FIELD_ERROR") { diff --git a/packages/vue-user/src/types/config.ts b/packages/vue-user/src/types/config.ts index d44e9fd7a..52ba3ca9d 100644 --- a/packages/vue-user/src/types/config.ts +++ b/packages/vue-user/src/types/config.ts @@ -16,6 +16,7 @@ interface DzangolabVueUserConfig { showCheckbox?: boolean; }; }; + updateEmail?: boolean; }; password?: { minLength: number; diff --git a/packages/vue-user/src/views/Profile.vue b/packages/vue-user/src/views/Profile.vue index 140b175da..499b517a4 100644 --- a/packages/vue-user/src/views/Profile.vue +++ b/packages/vue-user/src/views/Profile.vue @@ -1,5 +1,7 @@