Skip to content

Commit

Permalink
feat: 일정 등록 시 초기화 버튼 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
corinthionia committed Aug 2, 2023
1 parent f54ec06 commit c3bb51b
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/assets/icons/reset.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/atoms/resetButtonAtom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { atom } from 'recoil';

export const resetButtonState = atom<boolean>({
key: 'resetButton',
default: false,
});
66 changes: 66 additions & 0 deletions src/components/addButton/AddButton.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import styled from '@emotion/styled';
import theme from '../../styles/theme';

export const Wrapper = styled.div`
width: 100%;
max-width: 412px;
height: 90px;
position: fixed;
z-index: 3;
bottom: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
`;

export const BottomWrapper = styled.div`
width: 100%;
border-top: 1px solid ${theme.colors.gray02};
background: ${theme.colors.gray01};
display: flex;
justify-content: space-between;
padding: 10px 20px 28px 20px;
`;

export const ResetButtonWrapper = styled.div`
width: 52px;
height: 52px;
border-radius: 50%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: ${theme.colors.gray01};
filter: drop-shadow(0px 0px 7px rgba(0, 0, 0, 0.1));
cursor: pointer;
`;

export const ResetButton = styled.img`
width: 20px;
height: 20px;
`;

export const ResetText = styled.span`
color: ${theme.colors.gray05};
${theme.typography.medium06};
`;

export const BottomButton = styled.button`
width: 273px;
height: 52px;
border-radius: 6px;
${theme.typography.semibold03};
color: ${theme.colors.gray01};
background: ${theme.colors.purple06};
display: flex;
align-items: center;
justify-content: center;
`;
52 changes: 52 additions & 0 deletions src/components/addButton/AddButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import reset from '../../assets/icons/reset.svg';

import {
BottomButton,
BottomWrapper,
ResetButton,
ResetButtonWrapper,
ResetText,
Wrapper,
} from './AddButton.styles';

interface TableSelectedTypes {
[key: number]: string[];
}

interface AddButtonTypes {
handleApplyClick: () => void;
setTableSelected: React.Dispatch<React.SetStateAction<TableSelectedTypes>>;
setIsResetButtonClick: React.Dispatch<React.SetStateAction<boolean>>;
}

const AddButton = ({
setTableSelected,
handleApplyClick,
setIsResetButtonClick,
}: AddButtonTypes) => {
const handleResetClick = () => {
setTableSelected({});

const selected = document.querySelectorAll('.selected');

selected.forEach((element) => {
element.classList.remove('selected');
});

setIsResetButtonClick(true);
};

return (
<Wrapper>
<BottomWrapper>
<ResetButtonWrapper onClick={handleResetClick}>
<ResetButton src={reset} alt="reset" />
<ResetText>초기화</ResetText>
</ResetButtonWrapper>
<BottomButton onClick={handleApplyClick}>등록하기</BottomButton>
</BottomWrapper>
</Wrapper>
);
};

export default AddButton;
15 changes: 12 additions & 3 deletions src/components/addTimeTable/AddTimeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
TableWrapper,
} from './AddTimeTable.styles';
import Table from './Table';
import BottomButton from '../bottomButton/BottomButton';

import addPrevDisable from '../../assets/icons/addPrevDisable.png';
import addNextDisable from '../../assets/icons/addNextDisable.png';
Expand All @@ -24,7 +23,7 @@ import { API } from '../../utils/API';
import { getAddTimeTableInfo } from '../../utils/getAddTimeTableInfo';
import { getAllTimeRange } from '../../utils/getAllTimeRange';
import { getTimeRange } from '../../utils/getTimeRange';
import { AxiosError } from 'axios';
import AddButton from '../addButton/AddButton';

const AddTimeTable = ({
wrapperRef,
Expand All @@ -34,6 +33,9 @@ const AddTimeTable = ({
setSelected,
selectedMethod,
dates,
setTableSelected,
isResetButtonClick,
setIsResetButtonClick,
}: AddTimeTableTypes) => {
const { roomUUID } = useParams();
const navigate = useNavigate();
Expand Down Expand Up @@ -213,6 +215,8 @@ const AddTimeTable = ({
tablePage={tablePage}
selectedMethod={selectedMethod}
validDateChunks={validDateChunks}
isResetButtonClick={isResetButtonClick}
setIsResetButtonClick={setIsResetButtonClick}
/>
</TableWrapper>
<ScrollbarTrack ref={trackRef}>
Expand All @@ -225,11 +229,16 @@ const AddTimeTable = ({
/>
</ScrollbarTrack>

<BottomButton
{/* <BottomButton
onClick={handleApplyClick}
navigate={goToCurrent}
text="등록하기"
isActivated={true}
/> */}
<AddButton
setTableSelected={setTableSelected}
handleApplyClick={handleApplyClick}
setIsResetButtonClick={setIsResetButtonClick}
/>
</>
);
Expand Down
5 changes: 5 additions & 0 deletions src/components/addTimeTable/AddTimeTable.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export interface AddTimeTableTypes {
dates: string[];
selected: TableSelectedTypes;
setSelected: React.Dispatch<React.SetStateAction<TableSelectedTypes>>;
setTableSelected: React.Dispatch<React.SetStateAction<TableSelectedTypes>>;
isResetButtonClick: boolean;
setIsResetButtonClick: React.Dispatch<React.SetStateAction<boolean>>;
}

export interface TableType {
Expand All @@ -36,4 +39,6 @@ export interface TableType {
tablePage: number;
validDateChunks: Array<ChunkType[]>;
times: number[];
isResetButtonClick: boolean;
setIsResetButtonClick: React.Dispatch<React.SetStateAction<boolean>>;
}
5 changes: 4 additions & 1 deletion src/components/addTimeTable/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const Table = ({
tablePage,
validDateChunks,
times,
isResetButtonClick,
setIsResetButtonClick,
}: TableType) => {
const timeDetail = getTimeArray(times);

Expand All @@ -44,7 +46,8 @@ const Table = ({

useEffect(() => {
selectoRef.current.setSelectedTargets([]);
}, [selectedMethod]);
setIsResetButtonClick(false);
}, [selectedMethod, isResetButtonClick]);

const handleCellSelect = (e: any) => {
e.added.forEach((el: any) => {
Expand Down
10 changes: 0 additions & 10 deletions src/components/resultButton/ResultButton.stories.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions src/pages/addTime/AddTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Tooltip from '../../components/tooltip/Tooltip';
import { RoomTypes } from '../../types/roomInfo';
import { TableSelectedTypes } from './AddTime.types';
import { API } from '../../utils/API';
import { resetButtonState } from '../../atoms/resetButtonAtom';

const AddTime = () => {
const { roomUUID } = useParams();
Expand All @@ -37,6 +38,8 @@ const AddTime = () => {

const [selectedMethod, setSelectedMethod] =
useRecoilState(selectedMethodState);
const [isResetButtonClick, setIsResetButtonClick] =
useRecoilState(resetButtonState);

const [tableSelected, setTableSelected] = useState<TableSelectedTypes>({});
const [calendarSelected, setCalendarSelected] = useState<string[]>([]);
Expand Down Expand Up @@ -80,7 +83,10 @@ const AddTime = () => {
endTime={parseInt(endTime)}
selected={tableSelected}
setSelected={setTableSelected}
setTableSelected={setTableSelected}
dates={dates}
isResetButtonClick={isResetButtonClick}
setIsResetButtonClick={setIsResetButtonClick}
/>
) : (
<AddCalendar
Expand Down
5 changes: 5 additions & 0 deletions src/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ const typography = {
font-weight: 500;
line-height: 130%;
`,
medium06: css`
font-size: 10px;
font-weight: 500;
line-height: 130%;
`,

regular01: css`
font-size: 16px;
Expand Down

0 comments on commit c3bb51b

Please sign in to comment.