Skip to content

[WIP] Replace api type (part 4) #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions api/types/common.ts
Original file line number Diff line number Diff line change
@@ -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;
};
8 changes: 4 additions & 4 deletions api/types/user/activity.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions api/types/user/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './user';
6 changes: 2 additions & 4 deletions api/types/user/signInApiType.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 2 additions & 4 deletions api/types/user/signUpApiType.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
12 changes: 10 additions & 2 deletions api/types/user/user.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
5 changes: 2 additions & 3 deletions components/pages/profile/ProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions components/shared/organisms/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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';
import UserNavigation from './UserNavigation';
import { HeaderWrapper, Links } from './styled';

type Props = {
user?: User;
user?: CurrentUser;
signOut: ReturnType<typeof useSignOut>[0];
};

Expand Down
4 changes: 2 additions & 2 deletions components/shared/organisms/Header/UserNavigation.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) => {
Expand Down
6 changes: 4 additions & 2 deletions components/shared/organisms/ProfileForm/ProfileForm.tsx
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,7 +17,7 @@ type ValuesFromFormik = Parameters<UpdateUserFn>[0];

type ProfileFormContentProps = {
temporaryUrl: string | null;
profile: User;
profile: CurrentUser;
onSubmit: (values: ValuesFromFormik, formikHelpers: FormikHelpers<ValuesFromFormik>) => Promise<void>;
handleAvatarChange: (event: ChangeEvent<HTMLInputElement>) => void;
loading: boolean;
Expand Down
9 changes: 0 additions & 9 deletions domain/User.ts

This file was deleted.

9 changes: 2 additions & 7 deletions types/activityType.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down