Skip to content

Commit

Permalink
fix: resolve type error(s) causing build failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Prajwalism committed Jul 8, 2024
1 parent f23f6a5 commit 238e992
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/frontend/src/components/GoogleAuth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface UserProfileDetailsType {
has_user_profile: boolean;
}

export type IUserProfileDetailsType = UserProfileDetailsType | null;

const { BASE_URL } = process.env;

function GoogleAuth() {
Expand Down Expand Up @@ -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');
Expand Down
10 changes: 8 additions & 2 deletions src/frontend/src/services/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UserProfileDetailsType } from '@Components/GoogleAuth';
import { api } from '.';

export const signInUser = (data: any) => api.post('/users/login/', data);
Expand All @@ -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 });
26 changes: 14 additions & 12 deletions src/frontend/src/views/UserProfile/index.tsx
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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,
Expand All @@ -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,
});

Expand All @@ -59,18 +60,19 @@ export default function UserProfile() {

const { mutate: updateUserProfile } = useMutation<any, any, any, unknown>({
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();
Expand Down Expand Up @@ -110,10 +112,10 @@ export default function UserProfile() {
{userProfileActiveTab !== 1 && (
<Button
className="naxatw-absolute naxatw-bottom-4 naxatw-left-4 naxatw-bg-red"
leftIcon={'chevron_left'}
leftIcon="chevron_left"
onClick={onBackBtnClick}
>
{'Back'}
Back
</Button>
)}
<Button
Expand Down

0 comments on commit 238e992

Please sign in to comment.