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

모임을 만들 때 이전 시간를 지정하면 그 창은 넘어가지는 문제 수정 #502

Merged
merged 4 commits into from
Aug 31, 2024
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
14 changes: 11 additions & 3 deletions frontend/src/pages/MoimCreationPage/MoimCreationPage.util.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Validation Tests', () => {
describe('validateDate', () => {
beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date('2024-07-23T00:00:00Z'));
jest.setSystemTime(new Date('2024-07-23T10:00:00Z'));
});

afterAll(() => {
Expand All @@ -44,9 +44,17 @@ describe('Validation Tests', () => {
});

describe('validateTime', () => {
beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date('2024-07-23T10:00:00'));
});

afterAll(() => {
jest.useRealTimers();
});
it('00:00 형식이어야 true를 반환한다.', () => {
expect(validateTime('12:34')).toBe(true);
expect(validateTime('00:00')).toBe(true);
expect(validateTime('09:59')).toBe(false); // 현재 시간보다 이전
expect(validateTime('10:01')).toBe(true); // 현재 시간보다 이후
expect(validateTime('23:59')).toBe(true);
});

Expand Down
19 changes: 18 additions & 1 deletion frontend/src/pages/MoimCreationPage/MoimCreationPage.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,24 @@ export const validateTime = (time: string) => {
if (time === '') {
return true;
}
return POLICIES.hhmmRegex.test(time);
if (!POLICIES.hhmmRegex.test(time)) {
return false;
}

const now = new Date();
const [inputHour, inputMinute] = time.split(':').map(Number);
const inputTime = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
inputHour,
inputMinute,
);

if (inputTime < now) {
return false;
}
return true;
};

export const validatePlace = (place: string) => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/queryClient.ts
jaeml06 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const createQueryClient = () => {

const handleApiError = (error: Error) => {
Sentry.captureException(error);
console.log(error);
if (error instanceof ApiError) {
if (error.status === 401) {
removeToken();
Expand All @@ -49,6 +48,8 @@ const handleApiError = (error: Error) => {
if (error.message === '모임이 존재하지 않습니다.') {
window.location.href = GET_ROUTES.nowDarakbang.main();
return;
} else {
alert(error.message);
}
} else {
alert(error instanceof Error ? error.message : 'An error occurred');
Expand Down
Loading