From 1a99cb069aae1998b165414be2a1bf95c1ad518e Mon Sep 17 00:00:00 2001 From: Diana Safyanova Date: Fri, 7 Jan 2022 19:24:28 +0300 Subject: [PATCH 1/2] [REFACTOR] Replace api type --- api/types/common.ts | 10 ++++++++++ api/types/user/activity.ts | 8 ++++---- api/types/user/index.ts | 1 + api/types/user/signInApiType.ts | 6 ++---- api/types/user/signUpApiType.ts | 6 ++---- api/types/user/user.ts | 12 ++++++++++-- .../ActivityPagination/ActivityPagination.tsx | 2 +- components/pages/profile/ProfilePage.tsx | 5 ++--- components/shared/organisms/Header/Header.tsx | 4 ++-- .../shared/organisms/Header/UserNavigation.tsx | 4 ++-- .../shared/organisms/ProfileForm/ProfileForm.tsx | 6 ++++-- .../organisms/ProfileForm/ProfileFormContent.tsx | 4 ++-- domain/User.ts | 9 --------- 13 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 api/types/common.ts create mode 100644 api/types/user/index.ts delete mode 100644 domain/User.ts diff --git a/api/types/common.ts b/api/types/common.ts new file mode 100644 index 00000000..ff948c0a --- /dev/null +++ b/api/types/common.ts @@ -0,0 +1,10 @@ +import { NumberLiteral } from '@babel/types'; + +export type ID = string | number; + +export type PageInfo = { + endCursor: string; + hasNextPage: boolean; + hasPreviousPage: boolean; + startCursor: string; +}; diff --git a/api/types/user/activity.ts b/api/types/user/activity.ts index e48703b3..9e52b6b8 100644 --- a/api/types/user/activity.ts +++ b/api/types/user/activity.ts @@ -1,13 +1,13 @@ -import User from 'domain/User'; -import { PageInfo } from 'types/activityType'; +import type { ID, PageInfo } from '../common'; +import type { CurrentUser } from './user'; export type Activity = { + id: ID; body: string; createdAt: string | Date; event: string; - id: string | number; title: string; - user: User; + user: CurrentUser; }; export type ActivityEdge = { diff --git a/api/types/user/index.ts b/api/types/user/index.ts new file mode 100644 index 00000000..e5abc856 --- /dev/null +++ b/api/types/user/index.ts @@ -0,0 +1 @@ +export * from './user'; diff --git a/api/types/user/signInApiType.ts b/api/types/user/signInApiType.ts index f90a7ca3..d364f17d 100644 --- a/api/types/user/signInApiType.ts +++ b/api/types/user/signInApiType.ts @@ -1,8 +1,6 @@ -import User from 'domain/User'; +import { Me } from './user'; -export type SignInData = { - me: User; -}; +export type SignInData = Me; export type SignInVariables = { email: string; diff --git a/api/types/user/signUpApiType.ts b/api/types/user/signUpApiType.ts index b0ccc291..ffd8b2a4 100644 --- a/api/types/user/signUpApiType.ts +++ b/api/types/user/signUpApiType.ts @@ -1,8 +1,6 @@ -import User from 'domain/User'; +import { Me } from './user'; -export type SignUpData = { - me: User; -}; +export type SignUpData = Me; export type SignUpVariables = { avatarUrl?: string; diff --git a/api/types/user/user.ts b/api/types/user/user.ts index d1f45d02..d1096cd1 100644 --- a/api/types/user/user.ts +++ b/api/types/user/user.ts @@ -1,8 +1,16 @@ -import type User from 'domain/User'; import type { Uploaded } from 'hooks/useFileUpload'; +import type { ID } from '../common'; + +export type CurrentUser = { + id: ID; + email: string; + avatarUrl: string | null; + firstName: string; + lastName: string; +}; export type Me = { - me: User; + me: CurrentUser; }; export type UpdateUserData = Me; diff --git a/components/pages/activity/components/ActivityPagination/ActivityPagination.tsx b/components/pages/activity/components/ActivityPagination/ActivityPagination.tsx index 1da0820a..e492625d 100644 --- a/components/pages/activity/components/ActivityPagination/ActivityPagination.tsx +++ b/components/pages/activity/components/ActivityPagination/ActivityPagination.tsx @@ -2,7 +2,7 @@ import React from 'react'; import PaginationButton from 'components/shared/atoms/PaginationButton'; -import { PageInfo } from 'types/activityType'; +import { PageInfo } from 'api/types/common'; import { Wrapper, LeftPointerIcon, PageNumber, RightPointerIcon, prevButtonStyles, nextButtonStyles } from './styled'; diff --git a/components/pages/profile/ProfilePage.tsx b/components/pages/profile/ProfilePage.tsx index ab1bf3fd..e124c097 100644 --- a/components/pages/profile/ProfilePage.tsx +++ b/components/pages/profile/ProfilePage.tsx @@ -1,5 +1,6 @@ import React from 'react'; +import type { CurrentUser } from 'api/types/user'; import ErrorDecorator from 'decorators/ErrorDecorator'; import ErrorMessage from 'components/shared/atoms/ErrorMessage'; import WithAuth from 'lib/auth/withAuth'; @@ -12,12 +13,10 @@ import ProfileForm from 'components/shared/organisms/ProfileForm'; import { NotifierProvider } from 'contexts/NotifierContext'; import Notifier from 'components/shared/atoms/Notifier'; -import User from 'domain/User'; - const Profile = () => { const { loading, error, user } = useCurrentUser(); - const profile = (user as User) || {}; + const profile = (user as CurrentUser) || {}; const errorMessage = error ? new ErrorDecorator(error).getMessages() : null; return ( diff --git a/components/shared/organisms/Header/Header.tsx b/components/shared/organisms/Header/Header.tsx index bba5dff2..0b7c5c1f 100644 --- a/components/shared/organisms/Header/Header.tsx +++ b/components/shared/organisms/Header/Header.tsx @@ -2,7 +2,7 @@ import React from 'react'; import Link from 'next/link'; import { PROFILE, ACTIVITY, SIGNIN, SIGNUP } from 'config/routes'; -import User from 'domain/User'; +import type { CurrentUser } from 'api/types/user'; import type useSignOut from 'lib/apollo/hooks/actions/useSignOut'; import Logo from 'components/shared/atoms/Logo'; @@ -10,7 +10,7 @@ import UserNavigation from './UserNavigation'; import { HeaderWrapper, Links } from './styled'; type Props = { - user?: User; + user?: CurrentUser; signOut: ReturnType[0]; }; diff --git a/components/shared/organisms/Header/UserNavigation.tsx b/components/shared/organisms/Header/UserNavigation.tsx index 51b02eb6..c02838bb 100644 --- a/components/shared/organisms/Header/UserNavigation.tsx +++ b/components/shared/organisms/Header/UserNavigation.tsx @@ -1,6 +1,6 @@ import React, { useState, useRef, useEffect, useCallback } from 'react'; -import User from 'domain/User'; +import type { CurrentUser } from 'api/types/user'; import UserNavigationType from 'types/userNavigationType'; import ProfileImage from 'components/shared/atoms/ProfileImage'; @@ -9,7 +9,7 @@ import UserNavigationList from './UserNavigationList'; import { UserName, UserNavigationWrapper, UserNameWrapper } from './styled'; type Props = UserNavigationType & { - user: User; + user: CurrentUser; }; const UserNavigation = ({ user, links, actions }: Props) => { diff --git a/components/shared/organisms/ProfileForm/ProfileForm.tsx b/components/shared/organisms/ProfileForm/ProfileForm.tsx index 065674ef..0b186ed6 100644 --- a/components/shared/organisms/ProfileForm/ProfileForm.tsx +++ b/components/shared/organisms/ProfileForm/ProfileForm.tsx @@ -1,16 +1,18 @@ import React, { ChangeEvent, useMemo, useState } from 'react'; import type { FormikHelpers } from 'formik'; + +import type { CurrentUser } from 'api/types/user'; import useUpdateUser from 'lib/apollo/hooks/actions/useUpdateUser'; import usePresignFile from 'lib/apollo/hooks/actions/usePresignFile'; import { useFileUpload } from 'hooks/useFileUpload'; import type { Uploaded } from 'hooks/useFileUpload'; import ErrorDecorator from 'decorators/ErrorDecorator'; import { useNotifier } from 'contexts/NotifierContext'; -import User from 'domain/User'; + import ProfileFormContent from './ProfileFormContent'; type Props = { - profile: User; + profile: CurrentUser; }; const ProfileForm = ({ profile }: Props) => { diff --git a/components/shared/organisms/ProfileForm/ProfileFormContent.tsx b/components/shared/organisms/ProfileForm/ProfileFormContent.tsx index 51b31ea6..645ca0f9 100644 --- a/components/shared/organisms/ProfileForm/ProfileFormContent.tsx +++ b/components/shared/organisms/ProfileForm/ProfileFormContent.tsx @@ -2,7 +2,7 @@ import React, { ChangeEvent } from 'react'; import * as Yup from 'yup'; import { FormikHelpers } from 'formik'; -import User from 'domain/User'; +import type { CurrentUser } from 'api/types/user'; import { FormFieldConfig, FormFieldType } from 'types/formsType'; import type useUpdateUser from 'lib/apollo/hooks/actions/useUpdateUser'; @@ -17,7 +17,7 @@ type ValuesFromFormik = Parameters[0]; type ProfileFormContentProps = { temporaryUrl: string | null; - profile: User; + profile: CurrentUser; onSubmit: (values: ValuesFromFormik, formikHelpers: FormikHelpers) => Promise; handleAvatarChange: (event: ChangeEvent) => void; loading: boolean; diff --git a/domain/User.ts b/domain/User.ts deleted file mode 100644 index b72dd92c..00000000 --- a/domain/User.ts +++ /dev/null @@ -1,9 +0,0 @@ -type User = { - email: string; - avatarUrl: string | null; - id: number | string; - firstName: string; - lastName: string; -}; - -export default User; From 794ca4beea6305f13a0288f9c0abfa117dfe0380 Mon Sep 17 00:00:00 2001 From: Diana Safyanova Date: Fri, 7 Jan 2022 19:26:45 +0300 Subject: [PATCH 2/2] [REFACTOR] ID --- types/activityType.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/types/activityType.ts b/types/activityType.ts index c9e38567..e265a67c 100644 --- a/types/activityType.ts +++ b/types/activityType.ts @@ -1,12 +1,7 @@ -export type PageInfo = { - endCursor: string; - hasNextPage: boolean; - hasPreviousPage: boolean; - startCursor: string; -}; +import { ID } from 'api/types/common'; export type Activity = { - id: string | number; + id: ID; title: string; description: string; date: string;