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

[SKP-205-fix-bug] 자잘한 스타일 및 버그 수정 #75

Merged
merged 4 commits into from
Oct 22, 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
9 changes: 6 additions & 3 deletions src/components/Notification/NotificationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {NotificationDTO} from '../../hooks/queries/notification/useGetNotificati
import {usePatchNotification} from '../../hooks/mutations/notification/usePatchNotification';
import {useQueryClient} from '@tanstack/react-query';
import {NOTIFICATION_KEYS} from '../../hooks/queries/QueryKeys';
import {formatDate, getCategoryName} from '../../utils/pushUtils';

interface NotificationItemProps {
item: NotificationDTO;
Expand Down Expand Up @@ -46,12 +47,14 @@ export default function NotificationItem({item}: NotificationItemProps) {
]}
onPress={handleOnPress}>
<View style={styles.topBox}>
<Text style={styles.subtitle}>{item.type}</Text>
<Text style={styles.subtitle}>{getCategoryName(item.type)}</Text>
{!item.isChecked && <View style={styles.flag} />}
</View>

<Text style={styles.title}>{item.title}</Text>
<Text style={styles.date}>{item.createdAt}</Text>
<Text style={styles.title}>
{item.title} {item.body}
</Text>
<Text style={styles.date}>{formatDate(item.createdAt)}</Text>
</Pressable>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const styles = StyleSheet.create({
...flexBox('row', 'flex-start', 'center'),
gap: 10,
flex: 1,
paddingEnd: 20,
},
boxItemWSpace: {...flexBox('row', 'space-between'), width: '100%'},
text: {
Expand Down
4 changes: 4 additions & 0 deletions src/screens/Detail/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export default function Detail({navigation, route}: DetailProps) {
queryClient.invalidateQueries({
queryKey: LOCATION_KEYS.detail(String(id)),
});
queryClient.invalidateQueries({
queryKey: CATEGORY_KEYS.lists(),
});

navigation.pop();
bottomSheetRef.current?.close();
},
onError: e => {
Expand Down
40 changes: 40 additions & 0 deletions src/utils/pushUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,43 @@ export function parseNotificationData(data: string | object | undefined) {
console.error(e);
}
}

/**
* 카테고리 타입 별 이름 변환해 주는 함수
* @param type
*/
export function getCategoryName(type: string) {
if (type === 'userLocation') return '날짜 추천 받고 여행 떠나기';
else if (type === 'category') return '카테고리 리마인드';
else type;
}

/**
* ISO Date를 포맷팅해 주는 함수
* @param isoString
*/
export function formatDate(isoString: string): string {
try {
const date = new Date(isoString);

if (isNaN(date.getTime())) throw new Error('Invalid date');

const today = new Date();
const isToday =
date.getFullYear() === today.getFullYear() &&
date.getMonth() === today.getMonth() &&
date.getDate() === today.getDate();

if (isToday) {
return '오늘';
}

const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');

return `${year}.${month}.${day}`;
} catch (error) {
return isoString;
}
}