Skip to content

Commit

Permalink
fix: Context 초기값 undefined -> null로 바꾸기
Browse files Browse the repository at this point in the history
  • Loading branch information
simeunseo committed Jul 8, 2024
1 parent 3cc4c47 commit 41a251a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function OverallScheduleTable({
availableDates,
dataOverallSchedule,
}: OverallScheduleTableProps) {
const [clickedSlot, setClickedSlot] = useState<string | undefined>(undefined);
const [clickedSlot, setClickedSlot] = useState<string | null>(null);
const [clickedUserNames, setClickedUserNames] = useState<string[]>([]);

const getAvailableTimesPerDate = (
Expand Down
6 changes: 3 additions & 3 deletions src/pages/OverallSchedule/contexts/useClickContext.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Dispatch, SetStateAction, createContext, useContext } from 'react';

interface ClickContextType {
clickedSlot: string | undefined;
clickedSlot: string | null;
setClickedSlot: Dispatch<SetStateAction<ClickContextType['clickedSlot']>>;
clickedUserNames: string[];
setClickedUserNames: Dispatch<SetStateAction<ClickContextType['clickedUserNames']>>;
}

export const ClickContext = createContext<ClickContextType>({
clickedSlot: undefined,
setClickedSlot: () => undefined,
clickedSlot: null,
setClickedSlot: () => null,
clickedUserNames: [],
setClickedUserNames: () => [],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SelectContext, SelectedSlotType } from '../contexts/useSelectContext';
import { StepSlotsType, StepbottomItemsType } from '../types';

function SelectScheduleTable({ timeSlots, availableDates }: TimetableStructure) {
const [startSlot, setStartSlot] = useState<string | undefined>(undefined);
const [startSlot, setStartSlot] = useState<string | null>(null);
const [selectedSlots, setSelectedSlots] = useState<SelectedSlotType>({});

const { scheduleStep } = useScheduleStepContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const useSlotSeletion = () => {
});
removeOverlappedSlots(endSlot, dateOfStartSlot);
}
setStartSlot(undefined);
setStartSlot(null);
};

const handleDeleteSlot = (selectedEntryId: number) => {
Expand Down Expand Up @@ -62,11 +62,11 @@ const useSlotSeletion = () => {

const onClickSlot = (targetSlot: string, selectedEntryId?: number) => {
if (selectedEntryId !== undefined) {
if (startSlot === undefined) {
if (startSlot === null) {
handleDeleteSlot(selectedEntryId);
}
setStartSlot(undefined);
} else if (startSlot !== undefined) {
setStartSlot(null);
} else if (startSlot !== null) {
handleCompleteSlot(targetSlot);
} else {
handleSelectSlot(targetSlot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ScheduleStepContextType {

export const ScheduleStepContext = createContext<ScheduleStepContextType>({
scheduleStep: 'selectTimeSlot',
setScheduleStep: () => undefined,
setScheduleStep: () => null,
});

export function useScheduleStepContext() {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/selectSchedule/contexts/useSelectContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ export interface SelectedSlotType {
}

interface SelectContextType {
startSlot: string | undefined;
startSlot: string | null;
setStartSlot: Dispatch<SetStateAction<SelectContextType['startSlot']>>;
selectedSlots: SelectedSlotType;
setSelectedSlots: Dispatch<SetStateAction<SelectedSlotType>>;
}

export const SelectContext = createContext<SelectContextType>({
startSlot: undefined,
setStartSlot: () => undefined,
startSlot: null,
setStartSlot: () => null,
selectedSlots: {},
setSelectedSlots: () => undefined,
setSelectedSlots: () => null,
});

export function useSelectContext() {
Expand Down

0 comments on commit 41a251a

Please sign in to comment.