Skip to content

Instantly share code, notes, and snippets.

@Ah-ae
Ah-ae / weekly-after.tsx
Created June 2, 2024 06:24
리팩토링 이후
const DAYS_OF_WEEK = ['일', '월', '화', '수', '목', '금', '토'];
const today = dayjs().format('YYYY-MM-DD');
const getColumnTitle = (dateStr: string, index: number) => {
const dayOfMonth = dateStr.slice(8); // YYYY-MM-DD 에서 DD에 해당하는 부분
const isToday = dateStr === today;
return (
<>
<span className={`mr-px ${isToday ? 'p-[2px] bg-red-400 text-white' : 'p-px'} rounded-full`}>{parseInt(dayOfMonth)}</span>
@Ah-ae
Ah-ae / weekly-before.tsx
Created June 2, 2024 06:22
리팩토링 이전
import dayjs from 'dayjs';
import type { ColumnsType } from 'antd/es/table';
/** @returns {string[]} 'YYYY-MM-DD' 형식의 문자열을 요소로 갖는 배열 */
function getWeekDates(startDate: Date): string[] {
const dates = [];
const startDayOfWeek = startDate.getDay(); // 월요일이라면 1을 반환
for (let i = 0; i < 7; i++) {
const date = new Date(startDate);
import { useEffect, useRef } from 'react';
type Props = {
id?: number;
label?: React.ReactNode;
checked: boolean;
handleCheckbox: (checked: boolean, id: number) => void;
indeterminate?: boolean;
};
interface TableParams {
pagination: TablePaginationConfig;
sorter?: {
field: React.Key;
order: 'ascend' | 'descend' | undefined
};
}
function ProjectList() {
const [tableParams, setTableParams] = useState<TableParams>({
@Ah-ae
Ah-ae / axios_instance.ts
Last active September 14, 2023 06:44
axios instance 생성
import axios, { AxiosRequestConfig, AxiosInstance } from 'axios';
import { DEMO_BASE_URL } from '../utils/commons';
import { getToken } from '../utils/tokenManagement';
// 인증 정보가 필요하지 않은 instance
export const baseAPI = (url: string, options?: AxiosRequestConfig) => {
return axios.create({
baseURL: url,
headers: {
Accept: 'application/json',
import { describe, test, expect } from '@jest/globals';
import { checkEmail, checkPassword } from '../util/authorization/checkPassword';
describe('이메일 주소 유효성 검사', () => {
test('@가 없는 이메일 주소는 유효하지 않은 이메일 주소입니다.', () => {
const email = 'kimcoding.com';
const result = checkEmail(email);
expect(result).toBe(false);
});
test('.가 없는 이메일 주소는 유효하지 않은 이메일 주소입니다.', () => {
const StyledButton = styled.button<ButtonStyleType>`
width: ${(props) => props.width || '100%'};
background-color: ${(props) => props.backgroundColor || 'var(--blue300)'};
color: ${(props) => props.color || 'var(--white)'};
height: 50px;
padding: 10px 12px;
border-radius: 5px;
font-size: 1rem;
export const S_Button = styled.button`
// 가장 기본적인 파란색 버튼입니다. 화면 가로너비 전체를 차지합니다.
width: 100%;
height: 50px;
padding: 10px 12px;
border-radius: 5px;
color: var(--white);
font-size: 1rem;
background-color: var(--blue300);
:hover {
import { useState, useEffect } from 'react';
function useLocalStorage(key, initialState) {
const [state, setState] = useState(
() => JSON.parse(window.localStorage.getItem(key)) || initialState
);
useEffect(() => {
window.localStorage.setItem(key, JSON.stringify(state));
}, [key, state]);
import { useContext } from 'react';
import { userContext } from '../App.js';
function useAccessToken() {
const { tokens } = useContext(userContext);
const accessToken = tokens && tokens.accessToken;
return accessToken;
}
export default useAccessToken;