Skip to content

Commit

Permalink
Fix issues causing build failure (#63)
Browse files Browse the repository at this point in the history
* fix: resolve type error(s) causing build failure

* refactor: move types and interfaces to a different folder

* refactor: move types and interfaces to a different folder
  • Loading branch information
Prajwalism authored Jul 8, 2024
1 parent f23f6a5 commit 8676b8f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
9 changes: 1 addition & 8 deletions src/frontend/src/components/GoogleAuth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import { useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { Flex } from '@Components/common/Layouts';
import { toast } from 'react-toastify';

export interface UserProfileDetailsType {
id: string;
email: string;
img_url: string;
has_user_profile: boolean;
}
import { UserProfileDetailsType } from './types';

const { BASE_URL } = process.env;

Expand Down Expand Up @@ -41,7 +35,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
8 changes: 8 additions & 0 deletions src/frontend/src/components/GoogleAuth/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface UserProfileDetailsType {
id: string;
email: string;
img_url: string;
has_user_profile: boolean;
}

export type IUserProfileDetailsType = UserProfileDetailsType | null;
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { Flex, FlexColumn } from '@Components/common/Layouts';
import {
FormControl,
FormGroup,
Input,
Label,
Select,
} from '@Components/common/FormUI';
import { UserProfileDetailsType } from '@Components/GoogleAuth';
import { useForm } from 'react-hook-form';
import { FormControl, Input, Label } from '@Components/common/FormUI';
import ErrorMessage from '@Components/common/ErrorMessage';

export default function BasicDetails({ formProps }: { formProps: any }) {
const { register } = formProps;

console.log(formProps.formState.errors, 'formProps.formState.errors');

// const userProfile: UserProfileDetailsType =
// localStorage.getItem('userprofile');
return (
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/types';
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 });
2 changes: 1 addition & 1 deletion src/frontend/src/utils/sagaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export function withLoader(func: Function) {
};
}

export const nothing = '';
export const nothing = '';
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/types';
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 8676b8f

Please sign in to comment.