Skip to content

Commit

Permalink
feat : redux 데이터 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
wink4u committed Aug 17, 2023
1 parent b1e3197 commit 2a85822
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 35 deletions.
1 change: 1 addition & 0 deletions frontend/refill/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type Loginstate = {
token: string;
loginId: string;
pk: number;
exp: number;
};

export type Hosstate = {
Expand Down
19 changes: 10 additions & 9 deletions frontend/refill/src/components/aidiagnosis/NextPrevButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const NextPrevButtons: React.FC<LinkProps> = ({
navigate(-1);
};


const token = useSelector((state: RootState) => state.login.token);
const handleSubmit = () => {
const aiDiagnosisRequest = {
Expand All @@ -47,19 +46,21 @@ const NextPrevButtons: React.FC<LinkProps> = ({

if (imgFile) {
const convertToEnglishName = (filename: string) => {
const extension = filename.split('.').pop();
const nameWithoutExtension = filename.replace(`.${extension}`, '');

const englishName = Array.from(nameWithoutExtension).map((char) => {
const extension = filename.split(".").pop();
const nameWithoutExtension = filename.replace(`.${extension}`, "");

const englishName = Array.from(nameWithoutExtension)
.map((char) => {
return String.fromCharCode(97 + (char.charCodeAt(0) % 26));
}).join('');

})
.join("");

return `${englishName}.${extension}`;
};

const newFileName = convertToEnglishName(imgFile.name);
const newFile = new File([imgFile], newFileName, { type: imgFile.type });
console.log(newFile)
console.log(newFile);
formData.append("hairImg", newFile);
}
axios
Expand Down
23 changes: 13 additions & 10 deletions frontend/refill/src/components/consultReservation/SelectTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ const SelectTime: React.FC<SelectTimeProps> = ({

const getCurrentDate = () => {
const date = new Date();
return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
return `${date.getFullYear()}-${(date.getMonth() + 1)
.toString()
.padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`;
};

const isToday = (selectedDate: string) => {
return selectedDate === getCurrentDate();
};


const currentRealTime = getCurrentTime();

Expand All @@ -74,23 +75,25 @@ const SelectTime: React.FC<SelectTimeProps> = ({
const [nowTime, setNowTime] = useState<string | null>(null); // 추가된 상태
const isDisabled = (time: string) => {
const timeInMinutes = convertToMinutes(time);

// 현재 실제 시간보다 이전인지 확인 (오늘이 선택된 날짜라면)
const isBeforeCurrentTime = isToday(selectedDate) && timeInMinutes < convertToMinutes(getCurrentTime());

const isBeforeCurrentTime =
isToday(selectedDate) &&
timeInMinutes < convertToMinutes(getCurrentTime());

// startTime과 endTime을 기준으로 비활성화 판단
const outOfBounds =
const outOfBounds =
timeInMinutes < convertToMinutes(startTime) ||
timeInMinutes >= convertToMinutes(endTime);

// disabledTimes에서 시간만 추출하고 해당 시간이 포함되어 있는지 확인
const isTimeDisabled = disabledTimes
.map((t) => t.slice(0, 5))
.includes(time);

return outOfBounds || isTimeDisabled || isBeforeCurrentTime;
};

const handleTimeClick = (time: string) => {
setSelectedTime(time);
setNowSelected(time);
Expand Down
9 changes: 4 additions & 5 deletions frontend/refill/src/components/myPage/MyReservationReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ const MyReservationReport: React.FC<MyReservationReportProps> = ({
const sortedList = reservationList
?.filter(
(reservation) =>
new Date(reservation.startDateTime) >= thirtyOneMinutesAgo
new Date(reservation.startDateTime) >= thirtyOneMinutesAgo,
)
.slice()
.sort(
(a, b) =>
new Date(a.startDateTime).getTime() -
new Date(b.startDateTime).getTime()
new Date(b.startDateTime).getTime(),
);

const [currentIndex, setCurrentIndex] = useState(0);
Expand All @@ -80,8 +80,8 @@ const MyReservationReport: React.FC<MyReservationReportProps> = ({
setCurrentIndex((prevIndex) =>
Math.min(
prevIndex + slidesToShow,
reservationList.length - slidesToShow
)
reservationList.length - slidesToShow,
),
);
}
};
Expand Down Expand Up @@ -140,7 +140,6 @@ const MyReservationReport: React.FC<MyReservationReportProps> = ({
Next
</button>
</div>

</div>
<div className="px-10">
<CautionReservation />
Expand Down
3 changes: 2 additions & 1 deletion frontend/refill/src/hooks/UseLoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface User {
loginId: string;
role?: string;
iat?: number;
exp?: number;
exp: number;
id: number;
}

Expand Down Expand Up @@ -56,6 +56,7 @@ const UseLoginForm = (loginId: string, loginPassword: string, role: number) => {
token: checked.data.accessToken, // 액세스 토큰 값 설정
loginId: decode_token.loginId,
pk: decode_token.id,
exp: decode_token.exp,
}),
);

Expand Down
25 changes: 16 additions & 9 deletions frontend/refill/src/pages/hospital/DetailHospital.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ const DetailHospital: React.FC = () => {
};

// 리뷰 신고하기
const [openReportModal, setOpenReportModal] = useState<number|null>(null);
const handleOpenReportModal = (reviewId: number) => setOpenReportModal(reviewId);
const [openReportModal, setOpenReportModal] = useState<number | null>(null);
const handleOpenReportModal = (reviewId: number) =>
setOpenReportModal(reviewId);
const handleCloseReportModal = () => setOpenReportModal(null);

// 지도 생성 메서드
Expand Down Expand Up @@ -389,8 +390,8 @@ const DetailHospital: React.FC = () => {

// 의사 수정

const [modifyOpen, setModifyOpen] = useState<number|null>(null);
const handleMMOpen = (doctorId:number) => {
const [modifyOpen, setModifyOpen] = useState<number | null>(null);
const handleMMOpen = (doctorId: number) => {
setModifyOpen(doctorId);
};
const handleMMClose = () => {
Expand Down Expand Up @@ -427,7 +428,7 @@ const DetailHospital: React.FC = () => {
};

// 의사 삭제
const [deleteOpen, setDeleteOpen] = useState<number|null>(null);
const [deleteOpen, setDeleteOpen] = useState<number | null>(null);
const handleDMOpen = (doctorId: number) => {
setDeleteOpen(doctorId);
};
Expand Down Expand Up @@ -626,7 +627,9 @@ const DetailHospital: React.FC = () => {
<div className="flex">
<ModifyDoctor
open={modifyOpen === doctor.doctorId}
handleMOpen={()=>handleMMOpen(doctor.doctorId)}
handleMOpen={() =>
handleMMOpen(doctor.doctorId)
}
handleMClose={handleMMClose}
description={doctor.description}
education={doctor.educationBackgrounds}
Expand All @@ -643,7 +646,9 @@ const DetailHospital: React.FC = () => {
/>
<DeleteDoctor
open={deleteOpen === doctor.doctorId}
handleMOpen={()=>handleDMOpen(doctor.doctorId)}
handleMOpen={() =>
handleDMOpen(doctor.doctorId)
}
handleMClose={handleDMClose}
hospitalname={hospitalData.name}
doctorname={doctor.name}
Expand Down Expand Up @@ -795,8 +800,10 @@ const DetailHospital: React.FC = () => {
{ishospital ? (
<Grid item xs={2}>
<NotificationImportantIcon
sx={{ color: red[500], cursor: 'pointer' }}
onClick={()=>handleOpenReportModal(review.reviewId)}
sx={{ color: red[500], cursor: "pointer" }}
onClick={() =>
handleOpenReportModal(review.reviewId)
}
/>
<Modal
open={openReportModal === review.reviewId}
Expand Down
5 changes: 4 additions & 1 deletion frontend/refill/src/store/reducers/loginReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface LoginState {
hosid: number;
loginId: string;
pk: number;
exp: number;
}

const initialState: LoginState = {
Expand All @@ -21,18 +22,20 @@ const initialState: LoginState = {
hosid: 0,
loginId: "",
pk: 0,
exp: 0,
};

const loginSlice = createSlice({
name: "login",
initialState,
reducers: {
loginSuccess: (state, action: PayloadAction<Loginstate>) => {
const { islogin, token, loginId, pk } = action.payload;
const { islogin, token, loginId, pk, exp } = action.payload;
state.islogin = islogin;
state.token = token;
state.loginId = loginId;
state.pk = pk;
state.exp = exp;
console.log(state.islogin);
console.log(state.token);
},
Expand Down

0 comments on commit 2a85822

Please sign in to comment.