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

add. #79 플랜수정 삭제 조건 변경 #81

Merged
merged 1 commit into from
Jan 21, 2024
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
18 changes: 8 additions & 10 deletions src/components/templates/HomeTemplate/Plan/Dots/Dots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { PlanModalTemplate } from '@components/templates/PlanModalTemplate';
import { colors } from '@style/global-style';
import { Alert } from '@utils/Alert';
import { convertError } from '@utils/errors';
import { isPastDate } from '@utils/function';
import { AxiosError } from 'axios';
import dayjs from 'dayjs';
import { MouseEvent, useCallback, useMemo, useState } from 'react';
import { MouseEvent, useCallback, useState } from 'react';
import { useFormContext } from 'react-hook-form';
import { useDispatch } from 'react-redux';
import styled from 'styled-components';
Expand All @@ -24,7 +24,6 @@ type TProps = {

export const Dots = ({ planId, userId, selectDate, isProgress, endDate }: TProps) => {
const [isOpen, setOpen] = useState<number | null>(null);
const isSame = useMemo(() => dayjs(selectDate).isSame(new Date(), 'date'), [selectDate]);
const [isEditModal, setIsEditModal] = useState(false);
const dispatch = useDispatch();
const { setValue } = useFormContext<TRegisterFormValue>();
Expand All @@ -36,12 +35,9 @@ export const Dots = ({ planId, userId, selectDate, isProgress, endDate }: TProps
const handleClickOpenModal = useCallback(
(e: MouseEvent<SVGElement>) => {
e.stopPropagation();

if (isSame && isProgress) {
setOpen((prev) => (prev === planId ? null : planId));
}
setOpen((prev) => (prev === planId ? null : planId));
},
[planId, isSame, isProgress]
[planId]
);

const handleClickOpenEdit = useCallback(() => {
Expand Down Expand Up @@ -96,12 +92,14 @@ export const Dots = ({ planId, userId, selectDate, isProgress, endDate }: TProps
iconKey="dots"
size={25}
color={colors.darkGray}
cursor={isSame && isProgress ? 'pointer' : 'default'}
cursor={'pointer'}
onClick={handleClickOpenModal}
/>
<MiniModal className="dots" isOpen={isOpen === planId} handleClick={handleClose}>
<Button onClick={handleClickRemove(planId, userId)}>삭제</Button>
<Button onClick={handleClickOpenEdit}>수정</Button>
{(isProgress || isPastDate(new Date(), selectDate)) && (
<Button onClick={handleClickOpenEdit}>수정</Button>
)}
</MiniModal>

<PlanModalTemplate
Expand Down
7 changes: 4 additions & 3 deletions src/components/templates/HomeTemplate/Plan/Plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Spacing } from '@components/common/Spacing';
import { Dday } from '@components/templates/HomeTemplate/Plan/Dday';
import { Dots } from '@components/templates/HomeTemplate/Plan/Dots';
import { Stamp } from '@components/templates/HomeTemplate/Plan/Stamp';
import dayjs from 'dayjs';
import { isSameDate } from '@utils/function';
import { useCallback } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { useDispatch, useSelector } from 'react-redux';
Expand All @@ -26,6 +26,7 @@ export const Plan = (props: TProps) => {
endDate,
startDate,
recordStatus,
planStatus,
author,
publisher
} = props;
Expand Down Expand Up @@ -98,7 +99,7 @@ export const Plan = (props: TProps) => {
planId={planId}
userId={userInfo?.id ?? null}
selectDate={currentDate}
isProgress={recordStatus === ERecordStatus.inProgress}
isProgress={planStatus === ERecordStatus.inProgress}
endDate={endDate}
/>
</FormProvider>
Expand All @@ -108,7 +109,7 @@ export const Plan = (props: TProps) => {
selectDate={currentDate}
maxPage={Number(currentPage) + Number(target)}
currentPage={currentPage}
dday={dayjs(endDate).format('YYYY-MM-DD') === dayjs().format('YYYY-MM-DD')}
dday={isSameDate(new Date(), endDate)}
openSuccess={openSuccess}
openFailed={openFailed}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/utils/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const debounce = (callback: (...args: any[]) => void, time: number) => {
};

// 날짜가 동일한지 확인
export const isSameDate = (currentDate: string, compareDate: string) => {
export const isSameDate = (currentDate: string | Date, compareDate: string | Date) => {
const current = new Date(currentDate);
const compare = new Date(compareDate);

Expand All @@ -83,6 +83,7 @@ export const isSameDate = (currentDate: string, compareDate: string) => {
return true;
};

// 현재 날짜가 비교할 날짜보다 작은가?
export const isPastDate = (currentDate: string | Date, compareDate: string | Date) => {
const current = new Date(currentDate);
const compare = new Date(compareDate);
Expand Down
Loading