-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/AJD-Archive/Kkeujeok_Frontend…
… into fix/68
- Loading branch information
Showing
10 changed files
with
1,130 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Challenge, ChallengeResponse } from '../types/ChallengeType'; | ||
import { axiosInstance } from '../utils/apiConfig'; | ||
|
||
// * 챌린지 create | ||
export const createChallenge = async (data: FormData): Promise<void | string> => { | ||
try { | ||
const response = await axiosInstance.post('/challenges', data, { | ||
headers: { 'Content-Type': 'multipart/form-data' }, | ||
}); | ||
console.log(response.data); | ||
return ''; | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
// return null; | ||
} | ||
}; | ||
|
||
// * 챌린지 update | ||
export const patchChallenge = async (id: string, data: FormData): Promise<void> => { | ||
try { | ||
const response = await axiosInstance.patch(`/challenges/${id}`, data, { | ||
headers: { 'Content-Type': 'multipart/form-data' }, | ||
}); | ||
// console.log(response.data); | ||
return response.data.data.challengeId; | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
// return null; | ||
} | ||
}; | ||
|
||
// * 챌린지 get | ||
export const getSearchChallenge = async ( | ||
keyword: string | null, | ||
category: string | null, | ||
page: number, | ||
size: number | ||
): Promise<ChallengeResponse | null> => { | ||
try { | ||
console.log(keyword, category, '로 검색할게요'); | ||
const response = await axiosInstance.get(`/challenges/search`, { | ||
params: { | ||
category: category || '', // 빈 문자열은 전체 검색 | ||
keyword: keyword || '', | ||
page: page, | ||
size: size, | ||
}, | ||
}); | ||
console.log('챌린지 전체 데이터', response.data); | ||
return response.data.data; | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
return null; | ||
} | ||
}; | ||
|
||
// * 챌린지 상세보기 get | ||
export const getChallengeDetail = async (challengeId: string): Promise<Challenge | null> => { | ||
try { | ||
const response = await axiosInstance.get(`/challenges/${challengeId}`); | ||
// console.log(response.data.data); | ||
|
||
return response.data.data; | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
return null; | ||
} | ||
}; | ||
|
||
// * 챌린지 삭제 | ||
export const deleteChallenge = async (id: string): Promise<void> => { | ||
try { | ||
const response = await axiosInstance.delete(`/challenges/${id}`); | ||
|
||
console.log(response); | ||
} catch (error) { | ||
console.log('error'); | ||
} | ||
}; | ||
|
||
// * 챌린지 참여 | ||
export const joinChallenge = async (challengeId: string, dashboardId: string): Promise<void> => { | ||
try { | ||
const response = await axiosInstance.post(`/challenges/${challengeId}/${dashboardId}`); | ||
console.log(response.data); | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
} | ||
}; | ||
|
||
// * 챌린지 탈퇴 | ||
export const withdrawChallenge = async (id: string): Promise<void> => { | ||
try { | ||
const response = await axiosInstance.delete(`/challenges/${id}/withdraw`); | ||
|
||
console.log(response); | ||
} catch (error) { | ||
console.log('error'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import ErrorIcon from '../img/error.png'; | ||
import Flex from './Flex'; | ||
import { | ||
StyledModal, | ||
customStyles, | ||
ErrorImg, | ||
SubTitle, | ||
Title, | ||
BtnYes, | ||
BtnNo, | ||
} from '../styles/ModalStyled'; | ||
import * as S from '../styles/ChallengeStyled'; | ||
import { searchPersonalDashBoard } from '../api/BoardApi'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { DashboardItem } from '../types/PersonalDashBoard'; | ||
import { joinChallenge } from '../api/ChallengeApi'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export interface CustomModalProps { | ||
challengeId: string; | ||
onNoClick: () => void; | ||
fetchedData: () => void; | ||
} | ||
|
||
const JoinChallengeModal = ({ challengeId, onNoClick, fetchedData }: CustomModalProps) => { | ||
// 데이터 가져오기 | ||
const { data } = useQuery({ | ||
queryKey: ['personalDashboard'], | ||
queryFn: searchPersonalDashBoard, | ||
}); | ||
const [selectDashboard, setSelectDashboard] = useState<string>(''); | ||
|
||
// * 데이터가 로드되면 첫 번째 대시보드 ID를 기본값으로 설정 | ||
useEffect(() => { | ||
if ( | ||
data?.data.personalDashboardListResDto && | ||
data.data.personalDashboardListResDto.length > 0 | ||
) { | ||
const firstDashboardId = data.data.personalDashboardListResDto[0].dashboardId; | ||
if (firstDashboardId !== null && firstDashboardId !== undefined) { | ||
setSelectDashboard(String(firstDashboardId)); // 첫 번째 값을 기본 선택값으로 설정 | ||
} | ||
} | ||
}, [data]); | ||
|
||
// * 선택된 개인 대시보드 (챌린지 추가할 대시보드) | ||
const handleSelectChange = (event: React.ChangeEvent<HTMLSelectElement>) => { | ||
setSelectDashboard(event.target.value); | ||
}; | ||
|
||
// * 챌린지 참여 api | ||
const submitJoin = async () => { | ||
try { | ||
await joinChallenge(challengeId, selectDashboard); // 챌린지 참여 | ||
fetchedData(); // 참여 후 데이터 다시 불러오기 | ||
onNoClick(); // 모달 닫기 | ||
} catch (error) { | ||
console.error('Error joining challenge:', error); | ||
} | ||
}; | ||
|
||
return ( | ||
<StyledModal isOpen={true} shouldFocusAfterRender={false} style={customStyles}> | ||
{/* <ErrorImg src={ErrorIcon} alt="error_icon" /> */} | ||
<Flex flexDirection="column"> | ||
<Title>챌린지 참여하기</Title> | ||
<SubTitle | ||
style={{ | ||
marginTop: '0.7rem', | ||
}} | ||
> | ||
챌린지를 추가할 대시보드를 선택해주세요. | ||
</SubTitle> | ||
</Flex> | ||
<S.JoinSelect onChange={handleSelectChange}> | ||
{data?.data.personalDashboardListResDto?.map((item: DashboardItem) => ( | ||
<option | ||
key={item.dashboardId} | ||
value={ | ||
item.dashboardId !== null && item.dashboardId !== undefined ? item.dashboardId : '' | ||
} | ||
> | ||
{item.title} | ||
</option> | ||
))} | ||
</S.JoinSelect> | ||
|
||
<Flex> | ||
<BtnYes onClick={onNoClick}>취소</BtnYes> | ||
<BtnNo onClick={submitJoin}>참여</BtnNo> | ||
</Flex> | ||
</StyledModal> | ||
); | ||
}; | ||
|
||
export default JoinChallengeModal; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.