Skip to content

Commit

Permalink
Merge branch 'fe-dev' into feature/#854
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhokim98 authored Dec 18, 2024
2 parents 5ae1110 + 9032b09 commit 74b2c24
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 28 deletions.
11 changes: 11 additions & 0 deletions client/src/apis/request/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {User} from 'types/serviceType';

import {BASE_URL} from '@apis/baseUrl';
import {requestGet} from '@apis/fetcher';

export const requestGetUserInfo = async () => {
return await requestGet<User>({
baseUrl: BASE_URL.HD,
endpoint: `/api/users/mine`,
});
};
3 changes: 2 additions & 1 deletion client/src/components/Design/components/Image/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type ImageProps = React.ComponentProps<'img'> & {
/** @jsxImportSource @emotion/react */
export type ImageProps = React.ComponentProps<'img'> & {
src: string;
fallbackSrc?: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @jsxImportSource @emotion/react */
import type {Meta, StoryObj} from '@storybook/react';

import {Profile} from './Profile';

const meta: Meta<typeof Profile> = {
title: 'Components/Profile',
component: Profile,
tags: ['autodocs'],
parameters: {
layout: 'centered',
},
decorators: [
Story => (
<div style={{width: '200px', height: '200px', padding: '1rem'}}>
<Story />
</div>
),
],
args: {
src: 'https://wooteco-crew-wiki.s3.ap-northeast-2.amazonaws.com/%EC%9B%A8%EB%94%94%286%EA%B8%B0%29/g583lirp8yg.jpg',
size: 'large',
},
};

export default meta;

type Story = StoryObj<typeof meta>;

// Playground μŠ€ν† λ¦¬
export const Playground: Story = {};
26 changes: 26 additions & 0 deletions client/src/components/Design/components/Profile/Profile.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {css} from '@emotion/react';

import {Theme} from '@components/Design/theme/theme.type';

import {ProfileSize} from './Profile.type';

const SEMANTIC_SIZE: Record<ProfileSize, string> = {
small: '1rem',
medium: '1.75rem',
large: '3rem',
};

export const profileContainerStyle = (theme: Theme, size: ProfileSize) => {
return css({
display: 'flex',

width: SEMANTIC_SIZE[size],
height: SEMANTIC_SIZE[size],

borderRadius: '50%',

backgroundColor: theme.colors.white,

objectFit: 'cover',
});
};
13 changes: 13 additions & 0 deletions client/src/components/Design/components/Profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @jsxImportSource @emotion/react */
import {useTheme} from '@components/Design/theme/HDesignProvider';

import Image from '../Image/Image';

import {profileContainerStyle} from './Profile.style';
import {ProfileProps} from './Profile.type';

export const Profile = ({size = 'medium', ...profileProps}: ProfileProps) => {
const {theme} = useTheme();

return <Image aria-label="ν”„λ‘œν•„ 이미지" {...profileProps} css={profileContainerStyle(theme, size)} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {ImageProps} from '../Image/Image';

export type ProfileSize = 'small' | 'medium' | 'large';

export type ProfileProps = ImageProps & {
size?: ProfileSize;
};
8 changes: 3 additions & 5 deletions client/src/components/Loader/EventLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useQueries} from '@tanstack/react-query';
import {useSuspenseQueries} from '@tanstack/react-query';
import {useEffect} from 'react';

import {requestGetEvent} from '@apis/request/event';
Expand All @@ -16,7 +16,7 @@ import QUERY_KEYS from '@constants/queryKeys';
const EventLoader = ({children, ...props}: React.PropsWithChildren<WithErrorHandlingStrategy | null> = {}) => {
const eventId = getEventIdByUrl();

const queries = useQueries({
const queries = useSuspenseQueries({
queries: [
{queryKey: [QUERY_KEYS.event], queryFn: () => requestGetEvent({eventId, ...props})},
{
Expand Down Expand Up @@ -44,9 +44,7 @@ const EventLoader = ({children, ...props}: React.PropsWithChildren<WithErrorHand
}
}, [stepsData.data, stepsData.isSuccess, updateTotalExpenseAmount]);

const isLoading = queries.some(query => query.isLoading === true);

return !isLoading && children;
return children;
};

export default EventLoader;
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ const DesktopShareEventButton = ({onCopy}: DesktopShareEventButtonProps) => {
};

return (
<div style={{marginRight: '1rem'}}>
<Dropdown base="button" baseButtonText="μ •μ‚° μ΄ˆλŒ€ν•˜κΈ°">
<DropdownButton text="링크 λ³΅μ‚¬ν•˜κΈ°" onClick={copyAndToast} />
<DropdownButton text="QRμ½”λ“œλ‘œ μ΄ˆλŒ€ν•˜κΈ°" onClick={navigateQRPage} />
</Dropdown>
</div>
<Dropdown base="button" baseButtonText="μ •μ‚° μ΄ˆλŒ€ν•˜κΈ°">
<DropdownButton text="링크 λ³΅μ‚¬ν•˜κΈ°" onClick={copyAndToast} />
<DropdownButton text="QRμ½”λ“œλ‘œ μ΄ˆλŒ€ν•˜κΈ°" onClick={navigateQRPage} />
</Dropdown>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ const MobileShareEventButton = ({copyShare, kakaoShare}: MobileShareEventButtonP
};

return (
<div style={{marginRight: '1rem'}}>
<Dropdown base="button" baseButtonText="μ •μ‚° μ΄ˆλŒ€ν•˜κΈ°" onBaseButtonClick={initKakao}>
<DropdownButton text="링크 λ³΅μ‚¬ν•˜κΈ°" onClick={copyAndToast} />
<DropdownButton text="QRμ½”λ“œλ‘œ μ΄ˆλŒ€ν•˜κΈ°" onClick={navigateQRPage} />
<DropdownButton text="μΉ΄μΉ΄μ˜€ν†‘μœΌλ‘œ μ΄ˆλŒ€ν•˜κΈ°" onClick={kakaoShare} />
</Dropdown>
</div>
<Dropdown base="button" baseButtonText="μ •μ‚° μ΄ˆλŒ€ν•˜κΈ°" onBaseButtonClick={initKakao}>
<DropdownButton text="링크 λ³΅μ‚¬ν•˜κΈ°" onClick={copyAndToast} />
<DropdownButton text="QRμ½”λ“œλ‘œ μ΄ˆλŒ€ν•˜κΈ°" onClick={navigateQRPage} />
<DropdownButton text="μΉ΄μΉ΄μ˜€ν†‘μœΌλ‘œ μ΄ˆλŒ€ν•˜κΈ°" onClick={kakaoShare} />
</Dropdown>
);
};

Expand Down
1 change: 1 addition & 0 deletions client/src/constants/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const QUERY_KEYS = {
kakaoClientId: 'kakao-client-id',
kakaoLogin: 'kakao-login',
createdEvents: 'createdEvents',
userInfo: 'userinfo',
};

export default QUERY_KEYS;
16 changes: 16 additions & 0 deletions client/src/hooks/queries/user/useRequestGetUserInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {useSuspenseQuery} from '@tanstack/react-query';

import {requestGetUserInfo} from '@apis/request/user';

import QUERY_KEYS from '@constants/queryKeys';

const useRequestGetUserInfo = () => {
const {data} = useSuspenseQuery({
queryKey: [QUERY_KEYS.userInfo],
queryFn: requestGetUserInfo,
});

return {userInfo: data};
};

export default useRequestGetUserInfo;
3 changes: 3 additions & 0 deletions client/src/hooks/useEventPageLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import getEventIdByUrl from '@utils/getEventIdByUrl';
import useRequestGetEvent from './queries/event/useRequestGetEvent';
import useRequestGetAllMembers from './queries/member/useRequestGetAllMembers';
import useRequestGetSteps from './queries/step/useRequestGetSteps';
import useRequestGetUserInfo from './queries/user/useRequestGetUserInfo';

const useEventPageLayout = () => {
const eventId = getEventIdByUrl();
Expand All @@ -14,13 +15,15 @@ const useEventPageLayout = () => {
const {totalExpenseAmount} = useTotalExpenseAmountStore();
const {members} = useRequestGetAllMembers();
const {steps} = useRequestGetSteps();
const {userInfo} = useRequestGetUserInfo();
const billsCount = steps.flatMap(step => [...step.bills]).length;

const event = {
eventName,
bankName,
accountNumber,
createdByGuest,
userInfo,
};

const eventSummary = {
Expand Down
23 changes: 23 additions & 0 deletions client/src/pages/EventPage/EventPageFallback/EventPageLoading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Flex, Icon, IconButton, MainLayout, TopNav} from '@components/Design';
import {Footer} from '@components/Footer';

const EventPageLoading = () => {
return (
<MainLayout backgroundColor="gray">
<Flex justifyContent="spaceBetween" alignItems="center">
<TopNav>
<TopNav.Item routePath="/">
<IconButton variants="none">
<Icon iconType="heundeut" />
</IconButton>
</TopNav.Item>
<TopNav.Item displayName="ν™ˆ" routePath="/home" />
<TopNav.Item displayName="관리" routePath="/admin" />
</TopNav>
</Flex>
<Footer />
</MainLayout>
);
};

export default EventPageLoading;
26 changes: 20 additions & 6 deletions client/src/pages/EventPage/EventPageLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type {Event} from 'types/serviceType';

import {Outlet} from 'react-router-dom';
import {Link, Outlet} from 'react-router-dom';
import {useEffect} from 'react';

import {Profile} from '@components/Design/components/Profile/Profile';

import useEventPageLayout from '@hooks/useEventPageLayout';
import useShareEvent from '@hooks/useShareEvent';
import useAmplitude from '@hooks/useAmplitude';
Expand All @@ -14,6 +16,9 @@ import {Flex, Icon, IconButton, MainLayout, TopNav} from '@HDesign/index';

import {isMobileDevice} from '@utils/detectDevice';
import {updateMetaTag} from '@utils/udpateMetaTag';
import getImageUrl from '@utils/getImageUrl';

import {ROUTER_URLS} from '@constants/routerUrls';

export type EventPageContextProps = Event & {
isAdmin: boolean;
Expand Down Expand Up @@ -50,6 +55,8 @@ const EventPageLayout = () => {
};
}, []);

const isKakaoUser = event.userInfo && event.userInfo.isGuest === false;

return (
<MainLayout backgroundColor="gray">
<Flex justifyContent="spaceBetween" alignItems="center">
Expand All @@ -62,11 +69,18 @@ const EventPageLayout = () => {
<TopNav.Item displayName="ν™ˆ" routePath="/home" />
<TopNav.Item displayName="관리" routePath="/admin" />
</TopNav>
{isMobile ? (
<MobileShareEventButton copyShare={trackLinkShare} kakaoShare={trackKakaoShare} />
) : (
<DesktopShareEventButton onCopy={trackLinkShare} />
)}
<Flex alignItems="center" gap="0.75rem" margin="0 1rem 0 0">
{isMobile ? (
<MobileShareEventButton copyShare={trackLinkShare} kakaoShare={trackKakaoShare} />
) : (
<DesktopShareEventButton onCopy={trackLinkShare} />
)}
{isKakaoUser && (
<Link to={ROUTER_URLS.myPage}>
<Profile src={event.userInfo.profileImage ?? getImageUrl('runningDog', 'png')} size="medium" />
</Link>
)}
</Flex>
</Flex>
<Outlet context={outletContext} />
<Footer />
Expand Down
9 changes: 6 additions & 3 deletions client/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const MyPage = lazy(() => import('@pages/MyPage'));
const LoginRedirectPage = lazy(() => import('@pages/LoginPage/LoginRedirectPage'));
const LoginFailFallback = lazy(() => import('@pages/LoginPage/LoginFailFallback'));
const CreatedEventsPage = lazy(() => import('@pages/CreatedEventsPage/CreatedEventsPage'));
const EventPageLoading = lazy(() => import('@pages/EventPage/EventPageFallback/EventPageLoading'));

const router = createBrowserRouter([
{
Expand Down Expand Up @@ -76,9 +77,11 @@ const router = createBrowserRouter([
{
path: ROUTER_URLS.event,
element: (
<EventLoader>
<EventPage />
</EventLoader>
<Suspense fallback={<EventPageLoading />}>
<EventLoader>
<EventPage />
</EventLoader>
</Suspense>
),
children: [
{
Expand Down
2 changes: 2 additions & 0 deletions client/src/types/serviceType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export type Event = BankAccount & {

export type User = BankAccount & {
nickname: Nickname;
isGuest: boolean;
profileImage: string | null;
};

export interface Report {
Expand Down

0 comments on commit 74b2c24

Please sign in to comment.