Skip to content
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

feat: 공간 조건 적용 사용성 개선 (FE) #964

Merged
merged 5 commits into from
Apr 15, 2023
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
1 change: 1 addition & 0 deletions frontend/src/__mocks__/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const spaces: Spaces = {
reservationTimeUnit: 10,
reservationMinimumTimeUnit: 10,
reservationMaximumTimeUnit: 1440,
priorityOrder: 0,
enabledDayOfWeek: {
monday: true,
tuesday: true,
Expand Down
25 changes: 25 additions & 0 deletions frontend/src/api/setting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { QS } from '@toss/utils';
import { MapItem, Space } from '../types/common';
import { QuerySettingSummarySuccess } from '../types/response';
import api from './api';

export interface QuerySettingSummaryParams {
mapId: MapItem['mapId'];
spaceId: Space['id'];
selectedDateTime: string | null;
settingViewType: string | null;
}

export const querySettingSummary = ({
mapId,
spaceId,
selectedDateTime,
settingViewType,
}: QuerySettingSummaryParams) => {
return api.get<QuerySettingSummarySuccess>(
`/maps/${mapId}/spaces/${spaceId}/settings/summary${QS.create({
selectedDateTime: selectedDateTime,
settingViewType: settingViewType,
})}`
);
};
58 changes: 58 additions & 0 deletions frontend/src/components/Modal/SummaryModal.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import styled from 'styled-components';
import { Z_INDEX } from 'constants/style';

interface Props {
open?: boolean;
}

export const Overlay = styled.div<Props>`
display: ${({ open }) => (open ? 'flex' : 'none')};
position: fixed;
justify-content: center;
align-items: center;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: ${({ theme }) => theme.modalOverlay};
z-index: ${Z_INDEX.MODAL_OVERLAY};
overflow: scroll;
`;

export const Modal = styled.div`
width: 80%;
max-height: 70%;
min-width: 320px;
max-width: 768px;
position: absolute;
border-radius: 4px;
background-color: ${({ theme }) => theme.white};
overflow: auto;
`;

export const CloseButton = styled.button`
position: absolute;
padding: 0.5rem;
top: 0.5rem;
right: 1.5rem;
width: 1rem;
cursor: pointer;
border: none;
background: none;

&:hover {
opacity: 0.7;
}
`;

export const Inner = styled.div`
padding: 0.5rem 1rem;
`;

export const Header = styled.h2`
font-weight: 700;
padding: 1rem;
margin-bottom: 0.5rem;
`;

export const Content = styled.div``;
53 changes: 53 additions & 0 deletions frontend/src/components/Modal/SummaryModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { MouseEventHandler, PropsWithChildren } from 'react';
import { createPortal } from 'react-dom';
import { ReactComponent as CloseIcon } from 'assets/svg/close.svg';
import * as Styled from './SummaryModal.styles';

export interface Props {
open: boolean;
isClosableDimmer?: boolean;
showCloseButton?: boolean;
onClose: () => void;
}

let modalRoot = document.getElementById('modal');

const SummaryModal = ({
open,
isClosableDimmer,
showCloseButton,
onClose,
children,
}: PropsWithChildren<Props>): JSX.Element => {
if (modalRoot === null) {
modalRoot = document.createElement('div');
modalRoot.setAttribute('id', 'modal');
document.body.appendChild(modalRoot);
}

const handleMouseDownOverlay: MouseEventHandler<HTMLDivElement> = ({ target, currentTarget }) => {
if (isClosableDimmer && target === currentTarget) {
onClose();
}
};

return createPortal(
<Styled.Overlay open={open} onMouseDown={handleMouseDownOverlay}>
<Styled.Modal>
{open && showCloseButton && (
<Styled.CloseButton onClick={onClose}>
<CloseIcon />
</Styled.CloseButton>
)}
{open && children}
</Styled.Modal>
</Styled.Overlay>,
modalRoot
);
};

SummaryModal.Inner = Styled.Inner;
SummaryModal.Header = Styled.Header;
SummaryModal.Content = Styled.Content;

export default SummaryModal;
17 changes: 17 additions & 0 deletions frontend/src/hooks/query/useSettingSummary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AxiosError, AxiosResponse } from 'axios';
import { QueryKey, useQuery, UseQueryOptions, UseQueryResult } from 'react-query';
import { ErrorResponse, QuerySettingSummarySuccess } from 'types/response';
import { querySettingSummary, QuerySettingSummaryParams } from '../../api/setting';

const useSettingSummary = <TData = AxiosResponse<QuerySettingSummarySuccess>>(
params: QuerySettingSummaryParams,
options?: UseQueryOptions<
AxiosResponse<QuerySettingSummarySuccess>,
AxiosError<ErrorResponse>,
TData,
[QueryKey, QuerySettingSummaryParams]
>
): UseQueryResult<TData, AxiosError<ErrorResponse>> =>
useQuery(['getSettingSummary', params], () => querySettingSummary(params), options);

export default useSettingSummary;
28 changes: 19 additions & 9 deletions frontend/src/pages/GuestMap/units/ReservationForm.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,33 @@ export const InputsRow = styled.div`
}
`;

export const TimeFormMessageWrapper = styled.div`
export const SettingSummaryWrapper = styled.div`
display: flex;
flex-direction: column;
gap: 0.25rem;
margin-top: 0.5rem;
`;

export const TimeFormMessageList = styled.div`
display: flex;
flex-direction: column;
gap: 4px;
/**
* 세팅이 많아질 경우를 대비 (펼치기, 접기 용도)
*/
export const PartialSettingSummary = styled.p`
height: 80px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: horizontal;
white-space: pre-line;
line-height: normal;
font-size: 0.75rem;
color: ${({ theme }) => theme.gray[500]};
`;

export const TimeFormMessage = styled.p<{ fontWeight?: string }>`
left: 0.75rem;
bottom: -1rem;
export const SettingSummary = styled.p<{ fontWeight?: string }>`
white-space: pre-line;
line-height: normal;
font-size: 0.75rem;
height: 1em;
color: ${({ theme }) => theme.gray[500]};
${({ fontWeight }) => fontWeight && `font-weight: ${fontWeight}`};
`;
Expand Down
44 changes: 20 additions & 24 deletions frontend/src/pages/GuestMap/units/ReservationForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AxiosError } from 'axios';
import dayjs from 'dayjs';
import React, { useContext } from 'react';
import React, { useContext, useState } from 'react';
import { useMutation } from 'react-query';
import { useHistory } from 'react-router-dom';
import {
Expand All @@ -23,8 +23,9 @@ import useMember from 'hooks/query/useMember';
import { AccessTokenContext } from 'providers/AccessTokenProvider';
import { MapItem } from 'types/common';
import { ErrorResponse } from 'types/response';
import { formatTimePrettier, formatTimeWithSecond, isPastDate } from 'utils/datetime';
import { formatTimeWithSecond, isPastDate } from 'utils/datetime';
import { isNullish } from 'utils/type';
import useSettingSummary from '../../../hooks/query/useSettingSummary';
import { GuestMapFormContext } from '../providers/GuestMapFormProvider';
import * as Styled from './ReservationForm.styled';

Expand Down Expand Up @@ -64,6 +65,19 @@ const ReservationForm = ({ map }: Props) => {
);
};

const getSettingsSummary = useSettingSummary(
{
mapId: map?.mapId,
spaceId: parseInt(selectedSpaceId),
selectedDateTime: `${formValues.date}T${formatTimeWithSecond(
timePicker?.range.start ?? dayjs().tz()
)}${DATE.TIMEZONE_OFFSET}`,
settingViewType: 'FLAT',
},
{ enabled: selectedSpaceId !== null && !isNaN(parseInt(selectedSpaceId)) }
);
const settingsSummary = getSettingsSummary.data?.data?.summary ?? '';

const onSuccessCreateReservation = (
_: unknown,
{ reservation }: PostGuestReservationParams | PostMemberGuestReservationParams
Expand Down Expand Up @@ -165,28 +179,10 @@ const ReservationForm = ({ map }: Props) => {
/>
)}
{spacesMap?.[Number(selectedSpaceId)] && (
<Styled.TimeFormMessageWrapper>
<Styled.TimeFormMessage fontWeight="bold">예약 가능 시간</Styled.TimeFormMessage>
<Styled.TimeFormMessageList>
{spacesMap[Number(selectedSpaceId)].settings.map(
(
{
settingStartTime,
settingEndTime,
reservationMaximumTimeUnit,
reservationMinimumTimeUnit,
},
index
) => (
<Styled.TimeFormMessage key={index}>
{settingStartTime.slice(0, 5)} ~ {settingEndTime.slice(0, 5)}
(최소 {formatTimePrettier(reservationMinimumTimeUnit)}, 최대{' '}
{formatTimePrettier(reservationMaximumTimeUnit)})
</Styled.TimeFormMessage>
)
)}{' '}
</Styled.TimeFormMessageList>
</Styled.TimeFormMessageWrapper>
<Styled.SettingSummaryWrapper>
<Styled.SettingSummary fontWeight="bold">예약 가능 시간</Styled.SettingSummary>
<Styled.SettingSummary>{settingsSummary}</Styled.SettingSummary>
</Styled.SettingSummaryWrapper>
)}
</Styled.InputWrapper>

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/pages/GuestReservation/GuestReservation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ const GuestReservation = (): JSX.Element => {
<MemberGuestReservationForm
isEditMode={isEditMode}
space={getSpace.data?.data}
spaceId={spaceId}
mapId={mapId}
reservation={reservation}
date={date}
userName={userName ?? ''}
Expand All @@ -298,6 +300,8 @@ const GuestReservation = (): JSX.Element => {
) : (
<GuestReservationForm
isEditMode={isEditMode}
mapId={mapId}
spaceId={spaceId}
space={getSpace.data?.data}
reservation={reservation}
date={date}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ export const InputWrapper = styled.div`
}
`;

export const TimeFormMessageWrapper = styled.div`
export const SettingSummaryWrapper = styled.div`
display: flex;
flex-direction: column;
gap: 0.25rem;
margin-top: 0.5rem;
`;

export const TimeFormMessage = styled.p`
left: 0.75rem;
bottom: -1rem;
export const SettingSummary = styled.p<{ fontWeight?: string }>`
white-space: pre-line;
line-height: normal;
font-size: 0.75rem;
height: 1em;
color: ${({ theme }) => theme.gray[500]};
${({ fontWeight }) => fontWeight && `font-weight: ${fontWeight}`};
`;

export const ButtonWrapper = styled.div`
Expand Down
Loading