Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@ import UserIcon from 'web-components/src/components/icons/UserIcon';
import { AccountType } from 'generated/graphql';
import { TranslatorType } from 'lib/i18n/i18n.types';

import {
DEFAULT_NAME,
DEFAULT_PROFILE_BG,
DEFAULT_PROFILE_TYPE,
DEFAULT_PROFILE_USER_AVATAR,
} from 'pages/ProfileEdit/ProfileEdit.constants';

import { EditProfileFormSchemaType } from './EditProfileForm.schema';

export const getEditProfileFormInitialValues = (
_: TranslatorType,
): EditProfileFormSchemaType => ({
profileType: DEFAULT_PROFILE_TYPE,
name: _(DEFAULT_NAME),
profileImage: DEFAULT_PROFILE_USER_AVATAR,
backgroundImage: DEFAULT_PROFILE_BG,
description: '',
twitterLink: '',
websiteLink: '',
});

export const getRadioCardItems = (_: TranslatorType): RadioCardItem[] => [
{
id: 'individual',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Form from 'components/molecules/Form/Form';
import { useZodForm } from 'components/molecules/Form/hook/useZodForm';

import {
getEditProfileFormInitialValues,
getRadioCardItems,
LINKS_LABEL,
PROFILE_AVATAR_FILE_NAME,
Expand All @@ -58,14 +57,7 @@ export interface EditProfileFormProps {
onUpload?: (imageFile: File) => Promise<{ url: string }>;
}
const EditProfileForm: React.FC<React.PropsWithChildren<EditProfileFormProps>> =
({
children,
initialValues = getEditProfileFormInitialValues,
isDirtyRef,
onSubmit,
onSuccess,
onUpload,
}) => {
({ children, initialValues, isDirtyRef, onSubmit, onSuccess, onUpload }) => {
const { _ } = useLingui();
const form = useZodForm({
schema: editProfileFormSchema,
Expand Down
37 changes: 21 additions & 16 deletions web-marketplace/src/pages/ProfileEdit/ProfileEdit.Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,27 @@ export const ProfileEditMain = () => {
);
const fileNamesToDeleteRef = useRef<string[]>([]);

const initialValues: EditProfileFormSchemaType = useMemo(
() => ({
name: String(activeAccount?.name ? activeAccount?.name : DEFAULT_NAME),
description: String(activeAccount?.description?.trimEnd() ?? ''),
profileImage: String(
activeAccount?.image ? activeAccount?.image : defaultAvatar,
),
backgroundImage: String(
activeAccount?.bgImage ? activeAccount?.bgImage : DEFAULT_PROFILE_BG,
),
profileType: activeAccount?.type ?? DEFAULT_PROFILE_TYPE,
twitterLink: String(activeAccount?.twitterLink ?? ''),
websiteLink: String(activeAccount?.websiteLink ?? ''),
}),
[activeAccount, defaultAvatar],
);
const initialValues: EditProfileFormSchemaType = useMemo(() => {
const {
name,
description,
image,
bgImage,
type,
twitterLink,
websiteLink,
} = activeAccount ?? {};

return {
name: name ? name : _(DEFAULT_NAME),
description: description?.trimEnd() ?? '',
profileImage: image ? image : defaultAvatar,
backgroundImage: bgImage ? bgImage : DEFAULT_PROFILE_BG,
profileType: type ?? DEFAULT_PROFILE_TYPE,
twitterLink: twitterLink ?? '',
websiteLink: websiteLink ?? '',
};
}, [_, activeAccount, defaultAvatar]);

/* callbacks */
const onSubmit = useCallback(
Expand Down