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

[QA][QA] 다중 QA 처리 #181

Merged
merged 1 commit into from
Jul 2, 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 App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default function App() {
},
headerShadowVisible: false,
animationEnabled: false,
unmountOnBlur: true,
}}
>
{/* Tabs */}
Expand Down
10 changes: 5 additions & 5 deletions src/screens/Main/ChallengesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const ChallengesScreen = ({ navigation }) => {
const scrollViewRef = useRef<any>(null);

const { data: participationCheck } = useQuery(
['challenge', 'participation', 'check'],
ChallengeQueryKeys.getParticipationCheck(),
() => ChallengeAPI.getParticipationCheck(),
{ onSuccess: () => setParticipated(true) },
);

const { data: challengeParticipation, isLoading: isChallengeParticipationLoading } = useQuery(
['challenge', 'participation'],
ChallengeQueryKeys.getChallengeParticipation(),
ChallengeAPI.getChallengeParticipation,
{ enabled: participated },
);
Expand All @@ -50,17 +50,17 @@ const ChallengesScreen = ({ navigation }) => {
);

const { data: challengeCurrent, isLoading: isChallengeCurrentLoading } = useQuery(
['challenge', 'current', { limit: 5 }],
ChallengeQueryKeys.getChallengeCurrent({ limit: 5 }),
() => ChallengeAPI.getChallengeCurrent({ limit: 5 }),
);

const { data: challengeHistory, isLoading: isChallengeHIstoryLoading } = useQuery(
['challenge', 'history', { limit: 3 }],
ChallengeQueryKeys.getChallengeHistory({ limit: 5 }),
() => ChallengeAPI.getChallengeHistory({ limit: 3 }),
);

const { data: challengeHistoryCount, isLoading: isChallengeHIstoryCountLoading } = useQuery(
['challenge', 'count'],
ChallengeQueryKeys.getChallengeHistoryCount(),
() => ChallengeAPI.getChallengeHistoryCount(),
);

Expand Down
9 changes: 8 additions & 1 deletion src/screens/Main/challenge/ChallengeDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,22 @@ const ChallengeDetailScreen = ({ navigation, route }) => {
enabled: userId !== undefined,
},
);

const { data: MyCount, isLoading: isMyCountLoading } = useQuery(
ChallengeQueryKeys.getChallengeInsightCount({ writerId: String(userId) }),
() => ChallengeAPI.getChallengeInsightCount({ writerId: String(userId) }),
{ enabled: userId !== undefined },
);

const { data: count, isLoading: isCountLoading } = useQuery(
ChallengeQueryKeys.getChallengeFriendsCount({ challengeId }),
() => ChallengeAPI.getChallengeFriendsCount({ challengeId }),
);

const tabs = [
`전체기록 ${TotalCount?.insightNumber}`,
`내기록 ${MyCount?.insightNumber}`,
'친구',
`친구 ${(count?.challengerCount ?? 0) - 1}`,
];
const spacing = 16;
const tabWidth = (width - (tabs.length + 1) * spacing) / tabs.length;
Expand Down
25 changes: 17 additions & 8 deletions src/screens/Main/challenge/ChallengeEditScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import React, { useState, useLayoutEffect } from 'react';
import React, { useState, useLayoutEffect, useEffect, useMemo } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { Toast } from 'react-native-toast-message/lib/src/Toast';
import HeaderRightButton from '../../../components/header/HeaderRightButton';
import MainLottie from '../../../components/lotties/MainLottie';
import theme from '../../../theme/light';
import { ChallengeAPI } from '../../../utils/api/ChallengeAPI';
import { ChallengeAPI, ChallengeQueryKeys } from '../../../utils/api/ChallengeAPI';
import ChallengeEditOption from './ChallengeEditOption';
import { timeConverter } from './constant';
import { dateAdd, timeConverter } from './constant';

const ChallengeEditScreen = ({ navigation }) => {
const [myTopic, setMyTopic] = useState<string>('');
Expand All @@ -16,7 +16,7 @@ const ChallengeEditScreen = ({ navigation }) => {
const queryClient = useQueryClient();

const { data: challengeParticipation, isLoading: isChallengeParticipationLoading } = useQuery(
['challenge', 'participation'],
ChallengeQueryKeys.getChallengeParticipation(),
ChallengeAPI.getChallengeParticipation,
{
onSuccess: (response) => {
Expand All @@ -32,6 +32,13 @@ const ChallengeEditScreen = ({ navigation }) => {
queryClient.invalidateQueries(['challenge']);
Toast.show({ type: 'snackbar', text1: '목표를 수정했어요', position: 'bottom' });
},
onError: () => {
Toast.show({
type: 'snackbar',
text1: '달성 가능한 목표를 설정해주세요.',
position: 'bottom',
});
},
});

if (isChallengeParticipationLoading) {
Expand Down Expand Up @@ -59,6 +66,11 @@ const ChallengeEditScreen = ({ navigation }) => {
});
}, [myTopic, duration, insightPerWeek]);

const end = useMemo(
() => dateAdd(challengeParticipation?.startDate ?? '', duration),
[challengeParticipation?.startDate, duration, setDuration],
);

return (
<>
<View style={styles.Header}>
Expand Down Expand Up @@ -99,10 +111,7 @@ const ChallengeEditScreen = ({ navigation }) => {
option="챌린지 시작일"
value={timeConverter(challengeParticipation?.startDate ?? '')}
/>
<ChallengeEditOption
option="챌린지 종료일"
value={`${timeConverter(challengeParticipation?.endDate ?? '')} 까지`}
/>
<ChallengeEditOption option="챌린지 종료일" value={`${timeConverter(end)} 까지`} />
</>
);
};
Expand Down
8 changes: 7 additions & 1 deletion src/screens/Main/challenge/constant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import share from '../../../../assets/svgs/StatisticIcon/share';
import reaction from '../../../../assets/svgs/StatisticIcon/reaction';
import bookmark from '../../../../assets/svgs/StatisticIcon/bookmark';
import comment from '../../../../assets/svgs/StatisticIcon/comment';
Expand All @@ -8,6 +7,13 @@ export const timeConverter = (time: string) => {
return time.replace(/-/g, '. ');
};

export const dateAdd = (time: string, week: number) => {
const cur = new Date(time);
cur.setDate(cur.getDate() + 7 * week - 1);
const end = cur.toISOString().split('T')[0];
return end.replace(/-/g, '. ');
};

export const STATISTIC: Record<string, any>[] = [
{ name: 'viewCount', xml: view },
{ name: 'reactionCount', xml: reaction },
Expand Down
2 changes: 1 addition & 1 deletion src/screens/detailedPost/DetailedPostScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const DetailedPostScreen = ({ navigation, route }) => {
views={views}
url={insightResponse?.data?.link?.url ?? ''}
currentChallenge={getChallengeRecordResponse?.data?.challengeName}
contents={contents}
contents={insightResponse?.data?.contents}
reaction={insightResponse.data.reaction}
authorId={profile?.data?.authorId ?? -1}
recordText={
Expand Down
4 changes: 2 additions & 2 deletions src/screens/upload/UploadScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import FolderSheetContent from './FolderSheetContent';
import LinkSheetContent from './LinkSheetContent';
import UploadBottomContainer from './UploadBottomContainer';
import Toast from 'react-native-toast-message';
import { ChallengeAPI } from '../../utils/api/ChallengeAPI';
import { ChallengeAPI, ChallengeQueryKeys } from '../../utils/api/ChallengeAPI';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { InsightQueryKeys } from '../../utils/api/InsightAPI';

Expand All @@ -36,7 +36,7 @@ const UploadScreen = ({ navigation, route }) => {
const queryClient = useQueryClient();

const { data: challengeProgress, isLoading: isChallengeProgressLoading } = useQuery(
['challenge', 'participation'],
ChallengeQueryKeys.getChallengeProgress(),
ChallengeAPI.getChallengeProgress,
);
const snapPoints = useMemo(() => ['50%', '80%'], []);
Expand Down
5 changes: 2 additions & 3 deletions src/utils/api/BaseHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ httpClient.interceptors.response.use(
(error) => {
if (error.response.data.code === 402 || error.response.data.code == 411) {
navigate('SignUp', undefined);
return Promise.reject(error);
} else {
} else if (error.response.data.code !== 434) {
navigate('Error', { error });
return Promise.reject(error);
}
return Promise.reject(error);
},
);

Expand Down
16 changes: 16 additions & 0 deletions src/utils/api/ChallengeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ export const ChallengeQueryKeys = {
'count',
request,
],
getChallengeProgress: () => ['challenge', 'participation', 'progress'],
getParticipationCheck: () => ['challenge', 'participation', 'check'],
getChallengeParticipation: () => ['challenge', 'participation'],
getChallengeCurrent: (request: ChallengeCurrentGetRequest) => [
'challenge',
'current',
request.cursor,
request.limit,
],
getChallengeHistory: (request: ChallengeHistoryGetRequest) => [
'challenge',
'history',
request.cursor,
request.limit,
],
getChallengeHistoryCount: () => ['challenge', 'count'],
};

export const ChallengeAPI = {
Expand Down