@@ -84,12 +84,12 @@ export const DropdownUser = (props: Props) => {
-
{props.user?.first_name ?? props.dataUser.username}
+
{props.user?.user_id.first_name ?? props.dataUser.username}
{props.dataPerfil.map(({ description, path }) => (
diff --git a/src/features/navbar/organisms/NavbarTop.tsx b/src/features/navbar/organisms/NavbarTop.tsx
index fb3f36bf..2ad94798 100644
--- a/src/features/navbar/organisms/NavbarTop.tsx
+++ b/src/features/navbar/organisms/NavbarTop.tsx
@@ -1,28 +1,23 @@
'use client';
-import React, { useState } from 'react';
+import React, { useEffect, useState } from 'react';
+import { useContextUser } from '@/contexts/UserContext';
import { dataLogin, dataPerfil, dataUser } from '@/features/navbar/constants/dataNav';
import { DropdownUser } from '@/features/navbar/molecules/dropdown/DropdownUser';
import { ChangeLanguage } from '@/features/shared/atoms/changeLanguage/changeLanguage';
import ThemeSwitcher from '@/features/shared/atoms/swich/ThemeSwitcher';
-import style from './navbar-top.module.css';
+import { UserHasRole } from '@/features/shared/interfaces/UserHasRole';
-export interface User {
- phone: string | null;
- email: string | null;
- last_name: string | null;
- first_name: string | null;
- id: string;
- image_id: string | null;
-}
+import style from './navbar-top.module.css';
type Props = {
isPublic: boolean;
- user?: User;
+ user?: UserHasRole;
};
export const NavbarTop = (props: Props) => {
+ const { avatar, handleSetAvatar } = useContextUser();
const [isUserDropdownOpen, setIsUserDropdownOpen] = useState
(false);
const [isLangDropdownOpen, setIsLangDropdownOpen] = useState(false);
const handleDropdownUser = () => {
@@ -33,6 +28,15 @@ export const NavbarTop = (props: Props) => {
setIsLangDropdownOpen(!isLangDropdownOpen);
setIsUserDropdownOpen(false);
};
+ const handleSetAvatarUser = () => {
+ if (props.user?.user_id.image_id) {
+ handleSetAvatar(props.user.user_id.image_id);
+ }
+ };
+
+ useEffect(() => {
+ handleSetAvatarUser();
+ }, []);
return (
@@ -46,6 +50,7 @@ export const NavbarTop = (props: Props) => {
<>
{
const user = props.isPublic ? undefined : await fetchUser();
+
+ if (user) {
+ const metadata = await handleGetFile(user.user_id.image_id);
+ user.user_id.image_id = metadata.path;
+ }
+
return ;
};
diff --git a/src/features/profile/actions/ProfileAction.ts b/src/features/profile/actions/ProfileAction.ts
index 9f970f85..4fde4cee 100644
--- a/src/features/profile/actions/ProfileAction.ts
+++ b/src/features/profile/actions/ProfileAction.ts
@@ -1,12 +1,12 @@
'use server';
import { redirect, RedirectType } from 'next/navigation';
-import { updateRole } from '@/features/shared/actions/fetchUsers';
-import { SupabaseTable } from '@/features/shared/actions/supabaseTables';
-import { supabaseClientManager } from '@/lib/SupabaseClientManager';
+import { updateRole } from '@/features/shared/actions/roleActions';
+import { SupabaseTable } from '@/features/shared/constants/supabaseTables';
+import { supabaseServerClientManager } from '@/lib/SupabaseServerClientManager';
export const getSession = async () => {
- const supabase = supabaseClientManager.getPublicClient();
+ const supabase = supabaseServerClientManager.getServerPublicClient();
const { data, error } = await supabase.auth.getSession();
const user = data?.session?.user;
@@ -24,13 +24,13 @@ export const getSession = async () => {
type UpdatedUser = {
first_name?: string;
last_name?: string;
- phone?: number;
+ phone?: string;
role?: string;
account_active?: boolean;
};
export const updateUser = async (data: UpdatedUser, id: string) => {
- const supabase = supabaseClientManager.getPublicClient();
+ const supabase = supabaseServerClientManager.getServerPublicClient();
const phone = data.phone ? data.phone.toString() : null;
const { error } = await supabase
@@ -60,7 +60,7 @@ type UpdatedUserImage = {
};
export const updateUserImage = async (props: UpdatedUserImage) => {
- const supabase = supabaseClientManager.getPublicClient();
+ const supabase = supabaseServerClientManager.getServerPublicClient();
const { error } = await supabase
.from(SupabaseTable.PROFILES)
diff --git a/src/features/profile/interfaces/profileResponse.ts b/src/features/profile/interfaces/profileResponse.ts
index a62bb44c..a48a46fe 100644
--- a/src/features/profile/interfaces/profileResponse.ts
+++ b/src/features/profile/interfaces/profileResponse.ts
@@ -11,7 +11,7 @@ export interface ProfileResponse {
export type ProfileType = {
first_name?: string;
last_name?: string;
- phone?: number;
+ phone?: string;
};
export interface ProfilePayload extends ProfileType {}
diff --git a/src/features/profile/molecules/updateInfoUser/updateInfoUser.tsx b/src/features/profile/molecules/updateInfoUser/updateInfoUser.tsx
index 808d4905..3bc6cecc 100644
--- a/src/features/profile/molecules/updateInfoUser/updateInfoUser.tsx
+++ b/src/features/profile/molecules/updateInfoUser/updateInfoUser.tsx
@@ -11,13 +11,13 @@ import { updateUser } from '@/features/profile/actions/ProfileAction';
import { ProfileType as IProfileType } from '@/features/profile/interfaces/profileResponse';
import style from '@/features/profile/molecules/updateInfoUser/updateInfoUser.module.css';
import { profileUpdateSchema } from '@/features/profile/validations/profileUpdateSchema';
-import { User } from '@/features/shared/actions/fetchUsers';
import { ButtonAuth } from '@/features/shared/atoms/button/ButtonAuth';
import { InputForm, InputType } from '@/features/shared/atoms/inputForm/InputForm';
+import { UserHasRole } from '@/features/shared/interfaces/UserHasRole';
interface Props {
edit: boolean;
- userProfile: User;
+ userProfile: UserHasRole;
handleEditButton: () => void;
phoneNumber: string;
}
@@ -35,7 +35,7 @@ export const UpdateInfoUser = ({ edit, userProfile, handleEditButton, phoneNumbe
});
const onSubmit = handleSubmit(async (data: IProfileType) => {
- await toast.promise(updateUser(data, userProfile.id), {
+ await toast.promise(updateUser(data, userProfile.user_id.id), {
error: `${alert('error')}`,
success: `${alert('success')}`,
pending: `${alert('pending')}`,
@@ -54,7 +54,7 @@ export const UpdateInfoUser = ({ edit, userProfile, handleEditButton, phoneNumbe
className={style.infoUserEdit}
input_type={InputType.SIMPLE}
classNameError={style.inputError}
- placeholder={userProfile.first_name ?? t('p_name')}
+ placeholder={userProfile.user_id.first_name ?? t('p_name')}
disabled={!edit && true}
/>
@@ -67,19 +67,19 @@ export const UpdateInfoUser = ({ edit, userProfile, handleEditButton, phoneNumbe
className={style.infoUserEdit}
input_type={InputType.SIMPLE}
classNameError={style.inputError}
- placeholder={userProfile.last_name ?? t('p_lastname')}
+ placeholder={userProfile.user_id.last_name ?? t('p_lastname')}
disabled={!edit && true}
/>
{t('p_email')}:
-
{userProfile.email ?? <>{t('p_email')}>}
+
{userProfile.user_id.email ?? <>{t('p_email')}>}
errors={errors}
id={'phone'}
name={'phone'}
register={register}
- type={'number'}
+ type={'text'}
label={`${t('p_phone')}:`}
className={style.infoUserEdit}
input_type={InputType.SIMPLE}
diff --git a/src/features/profile/molecules/userImage/UserImage.tsx b/src/features/profile/molecules/userImage/UserImage.tsx
index 8be6edd5..2acc3ed6 100644
--- a/src/features/profile/molecules/userImage/UserImage.tsx
+++ b/src/features/profile/molecules/userImage/UserImage.tsx
@@ -1,7 +1,7 @@
-import React, { useState } from 'react';
+import React from 'react';
import { yupResolver } from '@hookform/resolvers/yup';
-import Image, { StaticImageData } from 'next/image';
+import Image from 'next/image';
import { useTranslations } from 'next-intl';
import { useTheme } from 'next-themes';
import { useForm } from 'react-hook-form';
@@ -9,13 +9,13 @@ import { toast } from 'react-toastify';
import IconPencil from '@/asset/images/pencil.svg';
import IconPencilWhite from '@/asset/images/pencilWhite.svg';
+import { useContextUser } from '@/contexts/UserContext';
import { updateUserImage } from '@/features/profile/actions/ProfileAction';
import style from '@/features/profile/molecules/userImage/user-image.module.css';
import { profileImageSchema } from '@/features/profile/validations/profileImageSchema';
-import { User } from '@/features/shared/actions/fetchUsers';
-import { handleGetFile, handleUploadFile } from '@/features/shared/actions/fileAction';
+import { handleGetFile, handleUploadFile } from '@/features/shared/actions/fileActions';
import { InputForm, InputType } from '@/features/shared/atoms/inputForm/InputForm';
-import { images } from '@/features/shared/hooks/images';
+import { UserHasRole } from '@/features/shared/interfaces/UserHasRole';
type IProfileForm = {
file?: object | string | null;
@@ -23,13 +23,12 @@ type IProfileForm = {
};
interface Props {
- userProfile: User;
+ userProfile: UserHasRole;
edit: boolean;
}
export const UserImage = ({ userProfile, edit }: Props) => {
- const { user } = images();
- const [imagePath, setImagePath] = useState(user);
+ const { avatar, handleSetAvatar } = useContextUser();
const alert = useTranslations('ToastUpdate');
const { theme } = useTheme();
const pencilToggle = theme === 'dark' ? IconPencilWhite : IconPencil;
@@ -58,11 +57,11 @@ export const UserImage = ({ userProfile, edit }: Props) => {
file.append('file', event.target.files[0]);
const fileMetadata = await handleUploadFile(file);
const data = {
- id: userProfile.id,
- first_name: userProfile.first_name,
- last_name: userProfile.last_name,
- phone: userProfile.phone,
- email: userProfile.email,
+ id: userProfile.user_id.id,
+ first_name: userProfile.user_id.first_name,
+ last_name: userProfile.user_id.last_name,
+ phone: userProfile.user_id.phone,
+ email: userProfile.user_id.email,
image_id: fileMetadata.id,
};
@@ -75,7 +74,7 @@ export const UserImage = ({ userProfile, edit }: Props) => {
});
const image = await handleGetFile(fileMetadata.id);
- setImagePath(image.path);
+ handleSetAvatar(image.path);
}
}
};
@@ -83,7 +82,7 @@ export const UserImage = ({ userProfile, edit }: Props) => {
return (
<>
-
+
{edit && (