Skip to content

Commit

Permalink
fix: fix form type in update profile
Browse files Browse the repository at this point in the history
  • Loading branch information
naumovski-filip committed Jul 11, 2023
1 parent 256d30c commit 9bb2fa5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/containers/Profiles/CreateProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { useNavigate } from 'react-router';

import profileStyles from './Profiles.module.scss';
import Form from './Form';
import type { ProfileFormValues } from './types';

import styles from '#src/pages/User/User.module.scss';
import { useAccountStore } from '#src/stores/AccountStore';
import type { ProfilePayload, ListProfilesResponse } from '#types/account';
import type { ListProfilesResponse } from '#types/account';
import { createProfile, listProfiles } from '#src/stores/AccountController';
import LoadingOverlay from '#src/components/LoadingOverlay/LoadingOverlay';
import type { UseFormOnSubmitHandler } from '#src/hooks/useForm';
Expand All @@ -34,17 +35,17 @@ const CreateProfile = () => {

const initialValues = {
name: '',
adult: true,
adult: 'true',
avatar_url: '',
pin: undefined,
};

const createProfileHandler: UseFormOnSubmitHandler<ProfilePayload> = async (formData, { setSubmitting, setErrors }) => {
const createProfileHandler: UseFormOnSubmitHandler<ProfileFormValues> = async (formData, { setSubmitting, setErrors }) => {
try {
const profile = (
await createProfile({
name: formData.name,
adult: formData.adult,
adult: formData.adult === 'true',
avatar_url: AVATARS[activeProfiles],
})
)?.responseData;
Expand Down
8 changes: 4 additions & 4 deletions src/containers/Profiles/EditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { useLocation, useNavigate, useParams } from 'react-router';
import profileStyles from './Profiles.module.scss';
import Form from './Form';
import DeleteProfile from './DeleteProfile';
import type { ProfileFormValues } from './types';

import styles from '#src/pages/User/User.module.scss';
import type { ProfilePayload } from '#types/account';
import LoadingOverlay from '#src/components/LoadingOverlay/LoadingOverlay';
import type { UseFormOnSubmitHandler } from '#src/hooks/useForm';
import Button from '#src/components/Button/Button';
Expand All @@ -31,7 +31,7 @@ const EditProfile = () => {
return {
id: profileDetails?.id || '',
name: profileDetails?.name || '',
adult: profileDetails?.adult ?? true,
adult: profileDetails?.adult ? 'true' : 'false',
avatar_url: profileDetails?.avatar_url || '',
pin: undefined,
};
Expand All @@ -41,12 +41,12 @@ const EditProfile = () => {
navigate('/u/profiles');
}

const updateProfileHandler: UseFormOnSubmitHandler<ProfilePayload> = async (formData, { setErrors, setSubmitting }) => {
const updateProfileHandler: UseFormOnSubmitHandler<ProfileFormValues> = async (formData, { setErrors, setSubmitting }) => {
try {
const response = await updateProfile({
id: id,
name: formData.name,
adult: formData.adult,
adult: formData.adult === 'true',
avatar_url: formData.avatar_url || profileDetails?.avatar_url,
});

Expand Down
6 changes: 3 additions & 3 deletions src/containers/Profiles/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { type SchemaOf, object, string } from 'yup';
import { useNavigate } from 'react-router';

import profileStyles from './Profiles.module.scss';
import type { ProfileFormValues } from './types';

import Button from '#src/components/Button/Button';
import Dropdown from '#src/components/Dropdown/Dropdown';
import FormFeedback from '#src/components/FormFeedback/FormFeedback';
import TextField from '#src/components/TextField/TextField';
import useForm, { UseFormOnSubmitHandler } from '#src/hooks/useForm';
import styles from '#src/pages/User/User.module.scss';
import type { ProfilePayload } from '#types/account';
import LoadingOverlay from '#src/components/LoadingOverlay/LoadingOverlay';

type Props = {
initialValues: ProfilePayload;
formHandler: UseFormOnSubmitHandler<ProfilePayload>;
initialValues: ProfileFormValues;
formHandler: UseFormOnSubmitHandler<ProfileFormValues>;
setFullName?: (name: string) => void;
};

Expand Down
1 change: 1 addition & 0 deletions src/containers/Profiles/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ProfileFormValues = Omit<ProfilePayload, 'adult'> & { adult: string };

0 comments on commit 9bb2fa5

Please sign in to comment.