From 238e992870b1b27055b957ee99758a0d5ac9a494 Mon Sep 17 00:00:00 2001 From: prajwalism Date: Mon, 8 Jul 2024 15:23:43 +0545 Subject: [PATCH] fix: resolve type error(s) causing build failure --- .../src/components/GoogleAuth/index.tsx | 3 ++- src/frontend/src/services/common.ts | 10 +++++-- src/frontend/src/views/UserProfile/index.tsx | 26 ++++++++++--------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/frontend/src/components/GoogleAuth/index.tsx b/src/frontend/src/components/GoogleAuth/index.tsx index bf71b3ca..dc950450 100644 --- a/src/frontend/src/components/GoogleAuth/index.tsx +++ b/src/frontend/src/components/GoogleAuth/index.tsx @@ -11,6 +11,8 @@ export interface UserProfileDetailsType { has_user_profile: boolean; } +export type IUserProfileDetailsType = UserProfileDetailsType | null; + const { BASE_URL } = process.env; function GoogleAuth() { @@ -41,7 +43,6 @@ function GoogleAuth() { const userDetails = await response2.json(); localStorage.setItem('userprofile', userDetails); setUserProfileDetails(userDetails); - console.log(userDetails, 'userDetails'); }; await completeLogin(); toast.success('Logged In Successfully'); diff --git a/src/frontend/src/services/common.ts b/src/frontend/src/services/common.ts index a8d1c82b..018a2336 100644 --- a/src/frontend/src/services/common.ts +++ b/src/frontend/src/services/common.ts @@ -1,3 +1,4 @@ +import { UserProfileDetailsType } from '@Components/GoogleAuth'; import { api } from '.'; export const signInUser = (data: any) => api.post('/users/login/', data); @@ -8,5 +9,10 @@ export const signInCallBackUrl = () => api.get('/users/callback/'); export const logoutUser = () => api.post('/user/logout/'); -export const postUserProfile = ({ userId, userProfile }) => - api.post(`/users/${userId}/profile`, { data: userProfile }); +export const postUserProfile = ({ + userId, + userProfile, +}: { + userId: number; + userProfile: UserProfileDetailsType; +}) => api.post(`/users/${userId}/profile`, { data: userProfile }); diff --git a/src/frontend/src/views/UserProfile/index.tsx b/src/frontend/src/views/UserProfile/index.tsx index 7b0866c6..b4097808 100644 --- a/src/frontend/src/views/UserProfile/index.tsx +++ b/src/frontend/src/views/UserProfile/index.tsx @@ -1,18 +1,18 @@ import { useTypedDispatch, useTypedSelector } from '@Store/hooks'; import { UserProfileHeader } from '@Components/UserProfile'; +import { useForm } from 'react-hook-form'; import { tabOptions } from '@Constants/index'; import { setCommonState } from '@Store/actions/common'; import { Button } from '@Components/RadixComponents/Button'; import { BasicDetails, OrganizationDetails, - PasswordSection, + // PasswordSection, } from '@Components/UserProfile/FormContents'; -import Tab from './UserProfileTabs'; -import { useForm } from 'react-hook-form'; import { useMutation } from '@tanstack/react-query'; import { postUserProfile } from '@Services/common'; -import { UserProfileDetailsType } from '@Components/GoogleAuth'; +import { IUserProfileDetailsType } from '@Components/GoogleAuth'; +import Tab from './UserProfileTabs'; const getActiveFormContent = (activeTab: number, formProps: any) => { switch (activeTab) { @@ -33,8 +33,9 @@ export default function UserProfile() { const userProfileActiveTab = useTypedSelector( state => state.common.userProfileActiveTab, ); - const userProfile: UserProfileDetailsType = - localStorage.getItem('userprofile'); + const userProfile = localStorage.getItem( + 'userprofile', + ) as IUserProfileDetailsType; const initialState = { name: null, @@ -47,7 +48,7 @@ export default function UserProfile() { confirm_password: null, }; - const { register, setValue, handleSubmit, reset, formState } = useForm({ + const { register, setValue, handleSubmit, formState } = useForm({ defaultValues: initialState, }); @@ -59,18 +60,19 @@ export default function UserProfile() { const { mutate: updateUserProfile } = useMutation({ mutationFn: postUserProfile, - onSuccess: (res: any) => { + onSuccess: () => { alert('updated'); // toast.success('UserProfile Updated Successfully'); }, onError: err => { + // eslint-disable-next-line no-console + console.log(err); // toast.error(err.message); }, }); const onSubmit = (data: any) => { - console.log(data, 'data'); - updateUserProfile(userProfile.id, data); + updateUserProfile(userProfile?.id, data); // if (userProfileActiveTab < 3) return; // createProject(data); // reset(); @@ -110,10 +112,10 @@ export default function UserProfile() { {userProfileActiveTab !== 1 && ( )}