Skip to content

Commit

Permalink
[Fix/#55] 오류 수정 (#56)
Browse files Browse the repository at this point in the history
* fix: 모집인원, 가격 숫자만 입력 가능하게

* fix: qr 카메라 꺼지게, 영역 제한

* fix: 비밀번호 눌렀을 때 hover 제거

* fix: 날짜, 시간 input css 수정

* fix: 토큰 만료시 response 처리
  • Loading branch information
alswlfl29 authored Jul 8, 2024
1 parent b70288f commit ba17c7c
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 28 deletions.
27 changes: 15 additions & 12 deletions src/apis/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { hostApi } from './interfaces/hostApi';
import { categoryApi } from './interfaces/categoryApi';
import { transactionApi } from './interfaces/transactionApi';
import { reservationApi } from './interfaces/reservationApi';
import { useNavigate } from 'react-router-dom';
import { useModal } from '../context/ModalContext';

export class ApiClient
implements
Expand Down Expand Up @@ -397,18 +395,23 @@ export class ApiClient
}
);

newInstance.interceptors.response.use((response) => {
if (response.status === 403) {
removeCookie('token');
removeCookie('username');
location.href = '/';
}
newInstance.interceptors.response.use(
(response) => {
console.log('dd', response);
return response;
},
(error) => {
console.log(error.response.status);
if (error.response.status === 403) {
alert('로그아웃되었습니다.');
removeCookie('token');
removeCookie('username');
location.href = '/hana';
}

if (response.status === 404) {
location.href = '/error';
return Promise.reject(error);
}
return response;
});
);

return newInstance;
};
Expand Down
8 changes: 8 additions & 0 deletions src/components/molecules/AddLessonInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ interface IProps {

export const AddLessonInput = forwardRef(
(props: IProps, ref: Ref<HTMLInputElement>) => {
const onInputNumber = (event: React.ChangeEvent<HTMLInputElement>) => {
if (props.type === 'number') {
event.target.value = event.target.value
.replace(/[^0-9.]/g, '')
.replace(/(\..*)\./g, '');
}
};
return (
<AddLessonInputLabel title={props.title}>
<input
Expand All @@ -18,6 +25,7 @@ export const AddLessonInput = forwardRef(
placeholder={props.placeholder}
maxLength={props.type === 'text' ? 50 : undefined}
min={props.type === 'number' ? 0 : undefined}
onInput={onInputNumber}
onChange={props.onChange}
className='w-full rounded border-[0.7px] border-hanaSilver text-xs placeholder:text-hanaSilver p-2 focus:outline-none'
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/molecules/AddLessonTimeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export const AddLessonTimeList: FC<IProps> = ({ onChangeTimes }) => {
<p className='w-full flex items-center justify-between gap-2'>
<input
type='date'
placeholder='클래스 날짜'
min={format(
new Date(new Date().setDate(new Date().getDate())),
'yyyy-MM-dd'
Expand Down
4 changes: 2 additions & 2 deletions src/components/molecules/PasswordKeypad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const PasswordKeypad: FC<IProps> = ({
{[1, -1, 2, -1, 3, 4, 5, 6, 7, 8, 9, 0].map((num, index) => (
<button
key={index}
className='font-hanaBold text-xl flex justify-center items-center hover:bg-white/20 hover:rounded-md'
className='font-hanaBold text-xl flex justify-center items-center active:bg-white/20 active:rounded-md'
onClick={() => clickKeypad(num)}
>
{num === -1 ? (
Expand All @@ -34,7 +34,7 @@ export const PasswordKeypad: FC<IProps> = ({
</button>
))}
<button
className='col-end-5 flex justify-center items-center'
className='col-end-5 flex justify-center items-center active:bg-white/20 active:rounded-md'
onClick={handleCancle}
>
<IoBackspaceOutline size={30} color='#B5B5B5' />
Expand Down
43 changes: 32 additions & 11 deletions src/components/molecules/QRScanner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QrScanner from 'qr-scanner';
import { FC, useEffect, useRef } from 'react';
import { FC, useEffect, useRef, useState } from 'react';
import { IoMdClose } from 'react-icons/io';
import { useNavigate } from 'react-router-dom';

Expand All @@ -14,7 +14,10 @@ export type qrUserInfo = {

export const QRScanner: FC<IProps> = ({ onClose }) => {
const navigate = useNavigate();
const videoRef = useRef(null);
const videoRef = useRef<HTMLVideoElement>(null);
const qrScannerRef = useRef<QrScanner>();
const qrBox = useRef<HTMLDivElement>(null);
const [qrOn, setQrOn] = useState<boolean>(true);

const QrOptions = {
// 핸드폰의 경우, 외부 카메라인지 셀프카메라인지
Expand All @@ -25,30 +28,44 @@ export const QRScanner: FC<IProps> = ({ onClose }) => {
highlightScanRegion: true,
};

const handleScan = (result: QrScanner.ScanResult, qrScanner: QrScanner) => {
const handleScan = (result: QrScanner.ScanResult) => {
const parsedData: qrUserInfo = JSON.parse(result.data);
qrScanner.destroy();

navigate('/qr-pay', {
state: {
accountId: parsedData.accountId,
balance: parsedData.balance,
},
});
};

useEffect(() => {
const videoElement = videoRef.current;
if (videoElement) {
const qrScanner = new QrScanner(
videoElement,
(result) => handleScan(result, qrScanner),
if (videoRef.current && !qrScannerRef.current) {
qrScannerRef.current = new QrScanner(
videoRef.current,
(result) => handleScan(result),
QrOptions
);
qrScanner.start();
}

qrScannerRef.current
?.start()
.then(() => setQrOn(true))
.catch((err) => {
if (err) setQrOn(false);
});

return () => {
if (!videoRef?.current) qrScannerRef.current?.stop();
};
}, []);

useEffect(() => {
if (!qrOn) alert('카메라 접근 허용을 해주세요.');
}, [qrOn]);

return (
<div className='relative top-0 left-0 flex flex-col w-full h-full justify-center items-center z-[60]'>
<div className='relative top-0 left-0 flex flex-col w-full h-full justify-center items-center z-[60] overflow-hidden bg-black'>
<IoMdClose
size={30}
color='white'
Expand All @@ -59,6 +76,10 @@ export const QRScanner: FC<IProps> = ({ onClose }) => {
QR코드를 스캔해 주세요.
</h1>
<video className='w-full h-screen object-cover' ref={videoRef}></video>
<div
className='absolute inset-0 border-y-[250px] border-x-[50px] border-black/70'
ref={qrBox}
></div>
</div>
);
};
12 changes: 12 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@
.custom-slider2 .slick-slide > div {
padding: 0 20px;
}

input[type='date'],
input[type='time'] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
margin: 0;
background-color: white;
min-height: 16px;
height: 32px;
padding: 8px;
}
2 changes: 1 addition & 1 deletion src/pages/main/HanaFunMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export const HanaFunMain = () => {

if (isGetAccountListError || isGetPopularLessonError) return <ErrorPage />;

if (isScan) return <QRScanner onClose={() => setIsScan(false)} />;
return (
<>
{isScan && <QRScanner onClose={() => setIsScan(false)} />}
{showKeypad && (
<AccountPwKeypad
handleClickedPassword={(pw: string) => sendAccountPassword(pw)}
Expand Down
9 changes: 8 additions & 1 deletion src/pages/search/LessonDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { LessonDateChoice } from '../../components/molecules/LessonDateChoice';
import { useQuery } from '@tanstack/react-query';
import { ApiClient } from '../../apis/apiClient';
import { Loading } from '../Loading';
import { ErrorPage } from '../ErrorPage';

export const LessonDetail = () => {
const navigate = useNavigate();
Expand All @@ -19,7 +20,11 @@ export const LessonDetail = () => {
const [copyLocation, setCopyLocation] = useState<boolean>(false);
const [materials, setMaterials] = useState<string[]>([]);
const [choiceModal, setChoiceModal] = useState<boolean>(false);
const { isLoading: isGetLessonLoading, data: lesson } = useQuery({
const {
isLoading: isGetLessonLoading,
data: lesson,
isError: isGetLessonError,
} = useQuery({
queryKey: ['lesson', lessonId],
queryFn: () => {
if (lessonId) {
Expand Down Expand Up @@ -67,6 +72,8 @@ export const LessonDetail = () => {

if (isGetLessonLoading || isGetLessonDateLoading) return <Loading />;

if (isGetLessonError) return <ErrorPage />;

return (
<>
{copyLocation && (
Expand Down

0 comments on commit ba17c7c

Please sign in to comment.