From d90b806cb8219e898e1b29f473c6cf224702f59d Mon Sep 17 00:00:00 2001 From: gerouvi <78085338+gerouvi@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:43:49 +0200 Subject: [PATCH] Implement edit profile screen (#777) A new view for profile editing. It also does a refactor of the dashboard layout to allow scrolling while keeping the background always visible. @selankon editions: - Moved the `src/components/OrganizationSaas/Dashboard/EditProfile.tsx` into `src/components/AccountSaas/EditProfile.tsx` - Created a `src/components/AccountSaas/Layout.tsx` to share inputs between forms - Same by shared types, created `src/components/AccountSaas/AccountTypes.ts` - It implements the EditProfile page on `elements` folder --- src/components/Account/EditProfile.tsx | 3 +- src/components/AccountSaas/AccountTypes.ts | 16 ++ src/components/AccountSaas/Create.tsx | 114 +--------- src/components/AccountSaas/EditProfile.tsx | 198 ++++++++++++++++++ src/components/AccountSaas/Layout.tsx | 94 +++++++++ src/components/Layout/SaasSelector.tsx | 62 +++++- .../OrganizationSaas/Dashboard/Layout.tsx | 29 +-- .../OrganizationSaas/Dashboard/Menu.tsx | 9 +- src/constants/index.ts | 1 + src/elements/OrganizationSaas/Edit.tsx | 41 +--- src/router/Router.tsx | 9 + src/themes/saas/components/textarea.ts | 2 +- 12 files changed, 413 insertions(+), 165 deletions(-) create mode 100644 src/components/AccountSaas/AccountTypes.ts create mode 100644 src/components/AccountSaas/EditProfile.tsx create mode 100644 src/components/AccountSaas/Layout.tsx diff --git a/src/components/Account/EditProfile.tsx b/src/components/Account/EditProfile.tsx index a2a6509d2..02c28e591 100644 --- a/src/components/Account/EditProfile.tsx +++ b/src/components/Account/EditProfile.tsx @@ -20,6 +20,7 @@ import { SubmitHandler, useForm } from 'react-hook-form' import { useTranslation } from 'react-i18next' import { BiTrash } from 'react-icons/bi' import fallback from '/assets/default-avatar.png' +import { REGEX_AVATAR } from '~constants' interface EditFormFields { name: string @@ -27,8 +28,6 @@ interface EditFormFields { avatar: string } -const REGEX_AVATAR = /^(https?:\/\/|ipfs:\/\/)/i - export const EditProfile = () => { const { account, fetchAccount } = useClient() const { update } = useOrganization() diff --git a/src/components/AccountSaas/AccountTypes.ts b/src/components/AccountSaas/AccountTypes.ts new file mode 100644 index 000000000..58c83f79d --- /dev/null +++ b/src/components/AccountSaas/AccountTypes.ts @@ -0,0 +1,16 @@ +export interface OrgInterface { + name: string + website: string + description: string + size: string + type: string + country: string + timezone: string + language: string + logo: string + header: string + subdomain: string + color: string +} + +export type CreateOrgParams = Partial diff --git a/src/components/AccountSaas/Create.tsx b/src/components/AccountSaas/Create.tsx index 7fa5e3a95..cf925ef0a 100644 --- a/src/components/AccountSaas/Create.tsx +++ b/src/components/AccountSaas/Create.tsx @@ -1,14 +1,4 @@ -import { - Box, - Flex, - FlexProps, - FormControl, - FormErrorMessage, - FormLabel, - Heading, - Text, - Textarea, -} from '@chakra-ui/react' +import { Box, Flex, FlexProps, FormControl, FormErrorMessage, Heading, Text } from '@chakra-ui/react' import { Button } from '@vocdoni/chakra-components' import { FormProvider, useForm } from 'react-hook-form' import { Trans, useTranslation } from 'react-i18next' @@ -17,35 +7,14 @@ import { useMutation, UseMutationOptions } from '@tanstack/react-query' import { useClient } from '@vocdoni/react-providers' import { useState } from 'react' import { useAccountCreate } from '~components/Account/useAccountCreate' +import { CreateOrgParams, OrgInterface } from '~components/AccountSaas/AccountTypes' +import { PrivateOrgFormData, PrivateOrgForm, PublicOrgForm } from '~components/AccountSaas/Layout' import { ApiEndpoints } from '~components/Auth/api' import { useAuth } from '~components/Auth/useAuth' -import CheckboxCustom from '~components/Layout/CheckboxCustom' -import InputCustom from '~components/Layout/InputCustom' -import { - CountriesTypesSelector, - MembershipSizeTypesSelector, - OrganzationTypesSelector, - SelectOptionType, -} from '~components/Layout/SaasSelector' import useDarkMode from '~src/themes/saas/hooks/useDarkMode' import LogoutBtn from '~components/AccountSaas/LogoutBtn' -interface OrgInterface { - name: string - website: string - description: string - size: string - type: string - country: string - timezone: string - language: string - logo: string - header: string - subdomain: string - color: string -} - -type CreateOrgParams = Partial +type FormData = PrivateOrgFormData & Pick // This specific error message should be ignored and not displayed in the UI. // Context: After login, a RemoteSigner is created and passed to the SDK via the useClient hook. @@ -65,25 +34,14 @@ const useSaasAccountCreate = (options?: Omit - export const AccountCreate = ({ children, ...props }: FlexProps) => { const { t } = useTranslation() const [isPending, setIsPending] = useState(false) - const { textColor, textColorBrand, textColorSecondary } = useDarkMode() + const { textColor, textColorSecondary } = useDarkMode() const methods = useForm() - const { - register, - handleSubmit, - formState: { errors }, - } = methods + const { handleSubmit } = methods const { signer } = useClient() @@ -94,11 +52,6 @@ export const AccountCreate = ({ children, ...props }: FlexProps) => { const error = saasError || accountError - const required = { - value: true, - message: t('form.error.field_is_required'), - } - const onSubmit = (values: FormData) => { setIsPending(true) // Create account on the saas to generate new priv keys @@ -136,60 +89,9 @@ export const AccountCreate = ({ children, ...props }: FlexProps) => { Create Your Organization - - Public Organization Information - - - - - - - - - Description - -