Skip to content

Commit

Permalink
bus refactor
Browse files Browse the repository at this point in the history
Origin/refactor/bus refactoring
  • Loading branch information
ftery0 authored Nov 25, 2024
2 parents b3f4fa0 + 14259a2 commit 84a4ebe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
29 changes: 10 additions & 19 deletions src/components/MyInfo/Contents/BusApply/BusOption/BusOption.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Bus } from "../../../../../types/busApply/busApply.type";
import * as S from "./style";
import { Bus } from '../../../../../types/busApply/busApply.type';
import * as S from './style';

interface Props {
data: Bus;
Expand All @@ -8,32 +8,23 @@ interface Props {
}

const BusOption = ({ data, isSelect, onChangeApplyBus }: Props) => {
const [busNumber, busName] = data.busName.split(" ");
const [busNumber, busName] = data.busName.split(' ');

return (
<S.BusOptionWrap
isSelect={isSelect}
onClick={() => onChangeApplyBus(data.id)}
>
{busNumber === "๋ฏธํƒ‘์Šน" ? (
<S.BusOptionWrap isSelect={isSelect} onClick={() => onChangeApplyBus(data.id)}>
{busNumber === '๋ฏธํƒ‘์Šน' ? (
<>
<S.BusOptionStationText isSelect={isSelect}>{busNumber}</S.BusOptionStationText>
<S.BusOptionStationText isSelect={isSelect}>
{busNumber}
</S.BusOptionStationText>
<S.BusOptionStationText isSelect={isSelect}>
({data.leaveTime.split(" ")[1].substring(0, 5)})
({data.leaveTime.split(' ')[1].substring(0, 5)})
</S.BusOptionStationText>
</>
) : (
<>
<S.BusOptionStationText isSelect={isSelect}>{busNumber} {data.applyCount}/{data.peopleLimit}</S.BusOptionStationText>
<S.BusOptionStationText isSelect={isSelect}>{busName}</S.BusOptionStationText>
<S.BusOptionStationText isSelect={isSelect}>
{busNumber}
</S.BusOptionStationText>
<S.BusOptionStationText isSelect={isSelect}>
{busName}
</S.BusOptionStationText>
<S.BusOptionStationText isSelect={isSelect}>
({data.leaveTime.split(" ")[1].substring(0, 5)})
({data.leaveTime.split(' ')[1].substring(0, 5)})
</S.BusOptionStationText>
</>
)}
Expand Down
25 changes: 14 additions & 11 deletions src/hooks/busApply/useBusApply.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { B1ndToast } from "@b1nd/b1nd-toastify";
import { useEffect, useState } from "react";
import busApplyRepository from "../../repository/busApply/busApply.repository";
import { Bus } from "../../types/busApply/busApply.type";
import { B1ndToast } from '@b1nd/b1nd-toastify';
import { useEffect, useState } from 'react';
import busApplyRepository from '../../repository/busApply/busApply.repository';
import { Bus } from '../../types/busApply/busApply.type';

const useBusApply = () => {
const [serverBusData, setServerBusData] = useState<Bus[]>([]);
const [selectedBusId, setSelectedBusId] = useState<number>(-1);
const [selectBusId, setSelectBusId] = useState<number>(-1);
const [busDate, setBusDate] = useState("");
const [busDate, setBusDate] = useState('');
const [isChange, setIsChange] = useState(false);

const mappingBusData = async () => {
Expand Down Expand Up @@ -46,10 +46,11 @@ const useBusApply = () => {
const onSubmitBusApply = async () => {
try {
await busApplyRepository.postBusApply({ idx: String(selectBusId) });
B1ndToast.showSuccess("๋ฒ„์Šค ์‹ ์ฒญ ์„ฑ๊ณต");
B1ndToast.showSuccess('๋ฒ„์Šค ์‹ ์ฒญ ์„ฑ๊ณต');
mappingBusData();
setSelectedBusId(selectBusId);
} catch (error) {
B1ndToast.showError("๋ฒ„์Šค ์‹ ์ฒญ ์‹คํŒจ");
B1ndToast.showError('๋ฒ„์Šค ์‹ ์ฒญ ์‹คํŒจ');
}
};

Expand All @@ -58,22 +59,24 @@ const useBusApply = () => {
await busApplyRepository.patchBusApply({
idx: String(selectBusId),
});
B1ndToast.showSuccess("๋ฒ„์Šค ์ˆ˜์ • ์„ฑ๊ณต");
B1ndToast.showSuccess('๋ฒ„์Šค ์ˆ˜์ • ์„ฑ๊ณต');
mappingBusData();
setSelectedBusId(selectBusId);
} catch (error) {
B1ndToast.showInfo("๋ฒ„์Šค ์ˆ˜์ • ์‹คํŒจ");
B1ndToast.showInfo('๋ฒ„์Šค ์ˆ˜์ • ์‹คํŒจ');
}
};
const deleteBusApply = async () => {
try {
await busApplyRepository.deleteBusApply({
idx: String(selectBusId),
});
B1ndToast.showSuccess("๋ฒ„์Šค ์‹ ์ฒญ ์ทจ์†Œ");
B1ndToast.showSuccess('๋ฒ„์Šค ์‹ ์ฒญ ์ทจ์†Œ');
mappingBusData();
setSelectBusId(-1);
setSelectedBusId(-1);
} catch (error) {
B1ndToast.showInfo("๋ฒ„์Šค ์‹ ์ฒญ์ทจ์†Œ ์‹คํŒจ");
B1ndToast.showInfo('๋ฒ„์Šค ์‹ ์ฒญ์ทจ์†Œ ์‹คํŒจ');
}
};
const onChangeApplyBus = (busId: number) => setSelectBusId(busId);
Expand Down
4 changes: 2 additions & 2 deletions src/repository/busApply/busApply.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class BusApplyRepository {
}

public async postBusApply({ idx }: BusApplyParam): Promise<void> {
await customAxios.post(`/bus/apply/${idx}`);
await customAxios.patch(`/bus/apply/status/${idx}`);
}

public async patchBusApply({ idx }: BusApplyParam): Promise<void> {
await customAxios.patch(`/bus/apply/${idx}`);
await customAxios.patch(`/bus/apply/status/${idx}`);
}

public async deleteBusApply({ idx }: BusApplyParam): Promise<void>{
Expand Down

0 comments on commit 84a4ebe

Please sign in to comment.