From 1b17a71a1b359cf922ea19718aac5cfbec1b3092 Mon Sep 17 00:00:00 2001 From: Sungyeon Jung Date: Tue, 9 Jul 2024 00:38:16 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=EB=82=A0=EC=A7=9C=20=EC=A7=80?= =?UTF-8?q?=EB=82=9C=20=EC=95=8C=EB=A6=BC=20=EC=95=84=EC=9D=B4=EC=BD=98=20?= =?UTF-8?q?=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ScheduleItem.tsx | 64 ++++++++++++++----- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/src/features/uos_lifestyle/academic_calendar/components/ScheduleItem.tsx b/src/features/uos_lifestyle/academic_calendar/components/ScheduleItem.tsx index c44b8675..0d2e2ff6 100644 --- a/src/features/uos_lifestyle/academic_calendar/components/ScheduleItem.tsx +++ b/src/features/uos_lifestyle/academic_calendar/components/ScheduleItem.tsx @@ -7,6 +7,7 @@ import Checkbox from './Checkbox'; import {ScheduleTabEnum} from '../constants'; import {ISchedule} from '../api/academicCalendarAPI.type'; import customShowToast from '../../../../configs/toast'; +import useModal from '../../../../hooks/useModal'; type ScheduleItemProps = { schedule: ISchedule; @@ -18,7 +19,7 @@ type ScheduleItemProps = { bookmarkHandler?: (param: number, flag: boolean) => void; notificationHandler?: ( param: number, - date: string, + startDate: string, isNotification: boolean, ) => void; delNotificationHandler?: (notificationId: number[]) => void; @@ -38,6 +39,7 @@ const ScheduleItem = ({ const [checked, setChecked] = useState(false); const [isBookmarked, setIsBookmarked] = useState(false); const [isNotificated, setIsNotificated] = useState(false); + const [isNotiInactive, setIsNotiInactive] = useState(false); const copyToClipboard = async () => { Clipboard.setString( `${schedule.title}\n${schedule.startDate}~${schedule.endDate}`, @@ -60,8 +62,16 @@ const ScheduleItem = ({ if (schedule.setNotification === undefined) return; setIsNotificated(schedule.setNotification); } + const standardDateStr = schedule.endDate; + const formattedStandardDateStr = standardDateStr.split('.').join('-'); + const standardDate = new Date(formattedStandardDateStr); // KST + const today = new Date(); + const result = today.getTime() - standardDate.getTime(); + if (result / 1000 / 60 / 60 >= 24) setIsNotiInactive(true); }, [schedule, tabType]); + useEffect(() => {}); + useEffect(() => { if (isChecked) return; setChecked(isChecked); @@ -139,9 +149,17 @@ const ScheduleItem = ({ customShowToast('deleteNotification'); }}> - + {isNotiInactive ? ( + + ) : ( + + )} @@ -153,20 +171,37 @@ const ScheduleItem = ({ onPress={() => { if (!notificationHandler) return; if (schedule.setNotification === undefined) return; - setIsNotificated(!isNotificated); - notificationHandler( - schedule.scheduleId, - schedule.startDate, - schedule.setNotification, - ); - customShowToast('addNotification'); + + const standardDateStr = schedule.endDate; + const formattedStandardDateStr = standardDateStr + .split('.') + .join('-'); + const standardDate = new Date(formattedStandardDateStr); // KST + const today = new Date(); + const result = today.getTime() - standardDate.getTime(); + if (result / 1000 / 60 / 60 >= 24) setIsNotificated(false); + else { + setIsNotificated(!isNotificated); + notificationHandler( + schedule.scheduleId, + schedule.startDate, + schedule.setNotification, + ); + customShowToast('addNotification'); + } }}> - + {isNotiInactive ? ( + + ) : ( + + )} @@ -203,7 +238,6 @@ const S = { border-radius: 16px; border: 1px solid ${colors.grey40}; background: #fff; - 성적열람제한해제수강지도기간(학업계획서,복학생상담) ${props => props.editable && `gap: 16px;`} `, From b40db621cca0ca65d78981e4420d78cf3e6f15fc Mon Sep 17 00:00:00 2001 From: Sungyeon Jung Date: Tue, 9 Jul 2024 00:42:32 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=EC=95=8C=EB=A6=BC=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=8B=9C=20=EB=AA=A8=EB=8B=AC=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EB=B0=8F=20=EC=9D=BC=EC=A0=95=20=EC=97=86=EC=9D=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../screens/AcademicCalendarScreen.tsx | 455 +++++++++++------- 1 file changed, 287 insertions(+), 168 deletions(-) diff --git a/src/features/uos_lifestyle/academic_calendar/screens/AcademicCalendarScreen.tsx b/src/features/uos_lifestyle/academic_calendar/screens/AcademicCalendarScreen.tsx index cbe8d1ac..23c8c97f 100644 --- a/src/features/uos_lifestyle/academic_calendar/screens/AcademicCalendarScreen.tsx +++ b/src/features/uos_lifestyle/academic_calendar/screens/AcademicCalendarScreen.tsx @@ -20,10 +20,10 @@ import Skeleton from '../../../../components/molecules/common/skeleton/Skeleton' import {getNotiTime} from '../utils'; import FilterButtonGroup from '../components/FilterButtonGroup'; import MonthlyFilter from '../components/MonthlyFilter'; +import useModal from '../../../../hooks/useModal'; const AcademicCalendarScreen = () => { const queryClient = useQueryClient(); - const inset = useSafeAreaInsets(); const navigation = useNavigation(); const date = new Date(); const week = ['일', '월', '화', '수', '목', '금', '토']; @@ -33,6 +33,9 @@ const AcademicCalendarScreen = () => { const currentDate: Date = new Date(); const [month, setMonth] = useState(currentDate.getMonth() + 1); const year: number = currentDate.getFullYear(); + + const [openModal, closeModal, Modal] = useModal('MODAL'); + const handlePreviousMonth = () => { setMonth(month === 1 ? 12 : month - 1); }; @@ -79,8 +82,11 @@ const AcademicCalendarScreen = () => { mutationFn: (params: SetNotificationParams) => { return CalendarAPI.setNotification(params); }, - onSuccess(data, variables, context) {}, - onError(data, variables, context) {}, + onSuccess: async () => { + await queryClient.invalidateQueries({ + queryKey: ['myScheduleItems'], + }); + }, }); const delNotificationMutation = useMutation({ @@ -88,20 +94,31 @@ const AcademicCalendarScreen = () => { mutationFn: (params: DeleteNotificationParams) => { return CalendarAPI.deleteNotification(params); }, + onSuccess: async () => { + await queryClient.invalidateQueries({ + queryKey: ['myScheduleItems'], + }); + }, + onError(error, variables, context) { + console.log(error); + }, }); const bookmarkMutation = useMutation({ - mutationKey: ['allScheduleItems'], + mutationKey: ['myScheduleItems', 'allScheduleItems'], mutationFn: (params: SetBookmarkParams) => CalendarAPI.setBookmark(params), onSuccess: async () => { - // await queryClient.invalidateQueries({ - // queryKey: ['allScheduleItems'], - // }); - }, - onError(data, variables, context) { - queryClient.invalidateQueries({ + console.log('나 성공했어'); + await queryClient.invalidateQueries({ queryKey: ['myScheduleItems'], }); + await queryClient.invalidateQueries({ + queryKey: ['allScheduleItems'], + }); + console.log('bb'); + }, + onError(error, variables, context) { + console.log(error); }, }); @@ -172,168 +189,215 @@ const AcademicCalendarScreen = () => { if (startDate <= today && today <= endDate) return item; } }; + // eslint-disable-next-line consistent-return + const messageOnFilter = (filterType: string, item: ISchedule[]) => { + if (filterType === 'ALL') { + if (item.length === 0) return '담은 학사일정을 확인할 수 있어요.'; + } + if (filterType === 'NOTIFICATION') { + if (item.filter(items => items.setNotification === true).length === 0) + return '알림을 설정한 학사일정이 없어요.'; + } + if (filterType === 'IN_PROGRESS') { + const result = item.filter(items => { + const formattedStartDate = items.startDate.split('.').join('-'); + const formattedEndDate = items.endDate.split('.').join('-'); + const startDate = new Date(formattedStartDate); + const endDate = new Date(formattedEndDate); + const today = new Date(); + if (startDate <= today && today <= endDate) return item; + return false; + }); + if (result.length === 0) return '진행 중인 학사 일정이 없어요'; + } + return ''; + }; return ( - -
navigation.goBack()} - /> - - - - - - - - setSelectedTab(ScheduleTabEnum.ALL)}> - + + + + + + + { + const alarmResultArray: ISchedule[] = []; + if (myScheduleItemData === undefined) return; + myScheduleItemData.forEach((item: ISchedule) => { + if (checkedList.includes(item.scheduleId)) + alarmResultArray.push(item); + }); + alarmResultArray.forEach((item: ISchedule) => { + if (item.notificationIds === undefined) return; + if (item.notificationIds.length !== 0) { + delNotificationHandler(item.notificationIds); } - typograph="bodyLarge" + }); + checkedList.forEach(item => { + bookmarkHandler(item, true); + }); + setEditable(false); + closeModal(); + }}> + + - - setSelectedTab(ScheduleTabEnum.MY_SCHEDULE)}> + + + { + closeModal(); + }}> + - - - {selectedTab === ScheduleTabEnum.ALL && ( - navigation.navigate('academic_calendar_search')}> - - - )} - - {selectedTab === ScheduleTabEnum.MY_SCHEDULE && ( - - + + + + +
navigation.goBack()} + /> + + + + - - {(() => { - if (!editable) { + + + + setSelectedTab(ScheduleTabEnum.ALL)}> + + + setSelectedTab(ScheduleTabEnum.MY_SCHEDULE)}> + + + + {selectedTab === ScheduleTabEnum.ALL && ( + navigation.navigate('academic_calendar_search')}> + + + )} + + {selectedTab === ScheduleTabEnum.MY_SCHEDULE && ( + + + + {(() => { + if (!editable) { + return ( + { + setEditable(true); + }}> + + + ); + } return ( - { - setEditable(true); - }}> - - - ); - } - return ( - <> - { - setEditable(false); - setCheckedList([]); - }}> - - - { - // 알림 해제 - const alarmResultArray: ISchedule[] = []; - if (myScheduleItemData === undefined) return; - myScheduleItemData.forEach((item: ISchedule) => { - if (checkedList.includes(item.scheduleId)) - alarmResultArray.push(item); - }); - alarmResultArray.forEach((item: ISchedule) => { - if (item.notificationIds === undefined) return; - if (item.notificationIds.length !== 0) { - delNotificationHandler(item.notificationIds); + <> + { + setEditable(false); + setCheckedList([]); + }}> + + + { + // 알림 해제 + openModal(); + }}> + 0 ? 'primaryBrand' : 'grey40' } - }); - checkedList.forEach(item => { - bookmarkHandler(item, true); - }); - - // await queryClient.invalidateQueries({ - // queryKey: ['myScheduleItems'], - // }); - setEditable(false); - }}> - 0 ? 'primaryBrand' : 'grey40' - } - typograph="labelLarge" - /> - - - ); - })()} - - - )} - {selectedTab === ScheduleTabEnum.ALL && ( - - - - )} - + typograph="labelLarge" + /> + + + ); + })()} + + + )} + {selectedTab === ScheduleTabEnum.ALL && ( + + + + )} + - - {selectedTab === ScheduleTabEnum.ALL - ? allScheduleItemData?.map((scheduleItem, idx: number) => { - return ( - - ); - }) - : myScheduleItemData - ?.filter(item => { - return filteredScheduleItem(selectedFilter, item); - }) - .map((scheduleItem, idx: number) => { + + {selectedTab === ScheduleTabEnum.ALL + ? allScheduleItemData?.map((scheduleItem, idx: number) => { return ( { isChecked={false} onCheckboxChange={checkboxHandler} tabType={selectedTab} - notificationHandler={notificationHandler} - delNotificationHandler={delNotificationHandler} + bookmarkHandler={bookmarkHandler} /> ); - })} - {(isFetchingAll || isFetchingMy) && } - - + }) + : myScheduleItemData + ?.filter(item => { + return filteredScheduleItem(selectedFilter, item); + }) + .map((scheduleItem, idx: number) => { + return ( + + ); + })} + {myScheduleItemData && selectedFilter && ( + + + + )} + + {(isFetchingAll || isFetchingMy) && } + + + ); }; @@ -361,6 +454,14 @@ const S = { display: flex; gap: 10px; `, + TxtContainer: styled.View` + display: flex; + width: 360px; + padding: 48px 16px; + justify-content: center; + align-items: center; + gap: 10px; + `, ScheduleContainer: styled.ScrollView` padding: 16px; display: flex; @@ -412,4 +513,22 @@ const S = { flex-direction: row; gap: 16px; `, + ModalContainer: styled.View` + display: flex; + padding-top: 24px; + `, + ModalHeader: styled.View` + display: flex; + gap: 8px; + padding: 0px 16px 16px 16px; + `, + ModalDelete: styled.View` + padding: 10px 16px; + border-top-width: 1px; + border-bottom-width: 1px; + border-color: ${colors.grey40}; + `, + ModalCancel: styled.View` + padding: 10px 16px 10px 16px; + `, }; From d7731b8f709eed4e0deeef6ea408099dcb2fa8d3 Mon Sep 17 00:00:00 2001 From: Sungyeon Jung Date: Tue, 9 Jul 2024 00:52:10 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20put=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/core/methods.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/api/core/methods.ts b/src/api/core/methods.ts index 692a0866..835f54eb 100644 --- a/src/api/core/methods.ts +++ b/src/api/core/methods.ts @@ -81,8 +81,19 @@ export const put = async ( clientType: ClientType = 'DEFAULT', ): KyJsonResponse => { const client = changeClient(clientType); - const putRes = await client.put(url, {json: body}); - return await putRes.json(); + try { + return body + ? await client.put(url, {json: body}).json() + : await client.put(url).json(); + } catch (error) { + const errorJson = await (error as any).response.json(); + const {message, status, code} = errorJson; + + throw new CustomError(status, code, message); + } + // const putRes = await client.put(url, {json: body}); + // console.log(putRes); + // return await putRes.json(); }; export const del = async (