Skip to content

Commit

Permalink
refactor: device type context 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
eonseok-jeon committed Aug 17, 2024
1 parent d36749a commit a8d5111
Show file tree
Hide file tree
Showing 43 changed files with 128 additions and 111 deletions.
6 changes: 3 additions & 3 deletions src/common/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useId, type ButtonHTMLAttributes, type ReactNode } from 'react';
import { useContext, useId, type ButtonHTMLAttributes, type ReactNode } from 'react';
import { Link, To } from 'react-router-dom';

import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import ButtonLoading from 'views/loadings/ButtonLoading';

import { buttonFontVar, container, outsideBox, paddings } from './style.css';
Expand All @@ -26,7 +26,7 @@ const Button = ({
isLink = false,
...buttonElementProps
}: ButtonProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const { disabled, type = 'button' } = buttonElementProps;
const Tag = isLink ? Link : 'button';

Expand Down
7 changes: 3 additions & 4 deletions src/common/components/Callout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { colors } from '@sopt-makers/colors';
import { IconAlertCircle } from '@sopt-makers/icons';
import { useContext, type HTMLAttributes, type ReactNode } from 'react';

import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';

import { buttonVar, container, warningWrapperVar } from './style.css';

import type { HTMLAttributes, ReactNode } from 'react';

interface CalloutProps extends HTMLAttributes<HTMLElement> {
children?: ReactNode;
size?: 'sm' | 'lg';
Button?: ReactNode;
}

const Callout = ({ children, size = 'sm', Button, ...calloutElementProps }: CalloutProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
return (
<article className={container[deviceType === 'DESK' ? size : deviceType]} {...calloutElementProps}>
<div className={warningWrapperVar[deviceType]}>
Expand Down
6 changes: 3 additions & 3 deletions src/common/components/Dialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forwardRef, type DialogHTMLAttributes, type ReactNode } from 'react';
import { forwardRef, useContext, type DialogHTMLAttributes, type ReactNode } from 'react';
import { createPortal } from 'react-dom';

import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';

import { containerVar } from './style.css';

Expand All @@ -10,7 +10,7 @@ interface DialogProps extends DialogHTMLAttributes<HTMLDialogElement> {
}

const Dialog = forwardRef<HTMLDialogElement, DialogProps>(({ children, ...dialogElementProps }: DialogProps, ref) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);

return createPortal(
<dialog ref={ref} className={containerVar[deviceType]} {...dialogElementProps}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { track } from '@amplitude/analytics-browser';
import { useContext } from 'react';
import { NavLink } from 'react-router-dom';

import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';

import { menuItemVar, menuLinkVar } from './style.css';

Expand All @@ -15,7 +16,7 @@ interface MenuItemProps {
}

const MenuItem = ({ text, path, target, amplitudeId, className, onClick }: MenuItemProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);

return (
<li className={`${className} ${menuItemVar[deviceType]}`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { reset, track } from '@amplitude/analytics-browser';
import { useContext, useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';

import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import { RecruitingInfoContext } from '@store/recruitingInfoContext';

import { dimmedBgVar, menuContainerVar, menuList, menuMobListVar } from './style.css';
import { MENU_ITEMS, MENU_ITEMS_MAKERS } from '../../contants';
import MenuItem from '../MenuItem';

const MenuList = ({ isMenuOpen, onClickMenuToggle }: { isMenuOpen?: boolean; onClickMenuToggle?: () => void }) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const navigate = useNavigate();
const { pathname } = useLocation();
const [isShown, setIsShown] = useState(isMenuOpen);
Expand Down
4 changes: 2 additions & 2 deletions src/common/components/Layout/components/Header/Nav/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { IconMenu, IconXClose } from '@sopt-makers/icons';
import { useContext } from 'react';

import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import { ThemeContext } from '@store/themeContext';
import { theme } from 'styles/theme.css';

import MenuList from './MenuList';
import { menuIconVar } from './style.css';

const Nav = ({ isMenuOpen, onClickMenuToggle }: { isMenuOpen: boolean; onClickMenuToggle: () => void }) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const { isLight } = useContext(ThemeContext);

return deviceType !== 'DESK' ? (
Expand Down
4 changes: 2 additions & 2 deletions src/common/components/Layout/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
import MakersDarkLogo from '@assets/MakersDarkLogo';
import MakersLogo from '@assets/MakersLogo';
import NowsoptLogo from '@assets/NowsoptLogo';
import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import { RecruitingInfoContext } from '@store/recruitingInfoContext';
import { ThemeContext } from '@store/themeContext';

Expand All @@ -13,7 +13,7 @@ import MenuList from './Nav/MenuList';
import { containerSizeVer, containerVar, logoVar } from './style.css';

const Header = () => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const [isMenuOpen, setIsMenuOpen] = useState(false);
const handleClickMenuToggle = () => {
setIsMenuOpen((prev) => !prev);
Expand Down
6 changes: 3 additions & 3 deletions src/common/components/Select/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IconChevronDown } from '@sopt-makers/icons';
import { ChangeEvent } from 'react';
import { ChangeEvent, useContext } from 'react';
import { useFormContext } from 'react-hook-form';

import { circle, containerVar, titleVar } from '@components/Input/components/TextBox/style.css';
import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';

import {
errorVar,
Expand All @@ -17,7 +17,7 @@ import {
import { SelectBoxProps } from './type';

const SelectBox = ({ label, name, options, size = 'sm', required, ...inputElementProps }: SelectBoxProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);

const { register, formState, clearErrors, getValues, setValue, setError } = useFormContext();
const { errors } = formState;
Expand Down
6 changes: 3 additions & 3 deletions src/common/components/Textarea/components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, type TextareaHTMLAttributes } from 'react';
import { useContext, useEffect, type TextareaHTMLAttributes } from 'react';
import { type FieldValues, type Path, useFormContext } from 'react-hook-form';

import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';

import {
containerVar,
Expand All @@ -26,7 +26,7 @@ const Input = <T extends FieldValues>({
isFileInput,
...textareaElements
}: InputProps<T>) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);

const {
watch,
Expand Down
6 changes: 3 additions & 3 deletions src/common/components/Textarea/components/Label/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fragment, type HTMLAttributes } from 'react';
import { Fragment, useContext, type HTMLAttributes } from 'react';

import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';

import { requireDot, labelStyleVar } from './style.css';

Expand All @@ -12,7 +12,7 @@ interface LabelProps extends HTMLAttributes<HTMLHeadingElement> {
}

const Label = ({ children, maxCount, required, label, ...headerElementProps }: LabelProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const questionArray = children.split('\n');
const firstEmptyIndex = questionArray.indexOf('');

Expand Down
6 changes: 3 additions & 3 deletions src/common/components/Title/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ReactNode } from 'react';
import { ReactNode, useContext } from 'react';

import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';

import { headingVar } from './style.css';

interface TitleProps {
children: ReactNode;
}
const Title = ({ children }: TitleProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
return <h1 className={headingVar[deviceType]}>{children}</h1>;
};

Expand Down
6 changes: 3 additions & 3 deletions src/views/ApplyPage/components/ApplyCategory/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { memo } from 'react';
import { memo, useContext } from 'react';
import { Link } from 'react-router-dom';

import { useDevice } from '@hooks/useDevice';
import useScrollPosition from '@hooks/useScrollPosition';
import { DeviceTypeContext } from '@store/deviceTypeContext';

import { CATEGORY } from './constant';
import { activeLinkStyleVar, categoryLinkStyleVar, categoryList, container, containerVar } from './style.css';
Expand All @@ -12,7 +12,7 @@ interface ApplyCategoryProps {
minIndex: number;
}
const ApplyCategory = memo(({ isReview, minIndex }: ApplyCategoryProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const { isScrollingDown, isScrollTop } = useScrollPosition(isReview ? 380 : 950);

return (
Expand Down
4 changes: 2 additions & 2 deletions src/views/ApplyPage/components/ApplyHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useContext } from 'react';

import Button from '@components/Button';
import Title from '@components/Title';
import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import { RecruitingInfoContext } from '@store/recruitingInfoContext';

import { buttonWrapper, headerContainerVar } from './style.css';
Expand All @@ -15,7 +15,7 @@ interface ApplyHeaderProps {
}

const ApplyHeader = ({ isReview, isLoading, onSaveDraft, onSubmitData }: ApplyHeaderProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const {
recruitingInfo: { soptName, season, group, isMakers },
} = useContext(RecruitingInfoContext);
Expand Down
4 changes: 2 additions & 2 deletions src/views/ApplyPage/components/ApplyInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ko } from 'date-fns/locale';
import { memo, useContext } from 'react';

import Callout from '@components/Callout';
import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import { RecruitingInfoContext } from '@store/recruitingInfoContext';

import {
Expand All @@ -19,7 +19,7 @@ import {
import { APPLY_INFO } from '../../constant';

const ApplyInfo = memo(({ isReview }: { isReview: boolean }) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const {
recruitingInfo: {
applicationStart,
Expand Down
4 changes: 2 additions & 2 deletions src/views/ApplyPage/components/BottomSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Checkbox from '@components/Checkbox';
import Contentbox from '@components/Checkbox/components/Contentbox';
import SelectBox from '@components/Select';
import { PRIVACY_POLICY } from '@constants/policy';
import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import { RecruitingInfoContext } from '@store/recruitingInfoContext';
import { SELECT_OPTIONS } from 'views/ApplyPage/constant';

Expand All @@ -16,7 +16,7 @@ interface BottomSectionProps {
}

const BottomSection = ({ isReview, knownPath }: BottomSectionProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const {
recruitingInfo: { isMakers },
} = useContext(RecruitingInfoContext);
Expand Down
6 changes: 4 additions & 2 deletions src/views/ApplyPage/components/CommonSection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useContext } from 'react';

import Textarea from '@components/Textarea';
import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import { sectionContainerVar, sectionTitleVar } from 'views/ApplyPage/style.css';
import { Answers, Questions } from 'views/ApplyPage/types';

Expand All @@ -15,7 +17,7 @@ interface CommonSectionProps {
}

const CommonSection = ({ isReview, refCallback, questions, commonQuestionsDraft }: CommonSectionProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const commonQuestionsById = commonQuestionsDraft?.reduce(
(acc, draft) => {
acc ? (acc[draft.id] = draft) : undefined;
Expand Down
6 changes: 3 additions & 3 deletions src/views/ApplyPage/components/DefaultSection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ChangeEvent, useState } from 'react';
import { ChangeEvent, useContext, useState } from 'react';
import { useFormContext } from 'react-hook-form';

import { InputLine, TextBox } from '@components/Input';
import Radio from '@components/Radio';
import SelectBox from '@components/Select';
import { VALIDATION_CHECK } from '@constants/validationCheck';
import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import { SELECT_OPTIONS } from 'views/ApplyPage/constant';
import { sectionTitleVar } from 'views/ApplyPage/style.css';
import { Applicant } from 'views/ApplyPage/types';
Expand Down Expand Up @@ -113,7 +113,7 @@ interface DefaultSectionProps {
}

const DefaultSection = ({ isMakers, isReview, refCallback, applicantDraft }: DefaultSectionProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const {
address,
birthday,
Expand Down
6 changes: 3 additions & 3 deletions src/views/ApplyPage/components/FileInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { track } from '@amplitude/analytics-browser';
import { nanoid } from 'nanoid';
import { ChangeEvent, useEffect, useRef, useState } from 'react';
import { ChangeEvent, useContext, useEffect, useRef, useState } from 'react';
import { useFormContext } from 'react-hook-form';

import 'firebase/compat/storage';
import { STATE_CHANGED, storage } from '@constants/firebase.ts';
import { VALIDATION_CHECK } from '@constants/validationCheck';
import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';

import IconPlusButton from './icons/IconPlusButton';
import {
Expand All @@ -32,7 +32,7 @@ const LIMIT_SIZE = 1024 ** 2 * 50; // 50MB
const ACCEPTED_FORMATS = '.pdf';

const FileInput = ({ section, id, isReview, disabled, defaultFile }: FileInputProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const inputRef = useRef<HTMLInputElement>(null);

const [uploadPercent, setUploadPercent] = useState(-1);
Expand Down
6 changes: 4 additions & 2 deletions src/views/ApplyPage/components/Info/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useDevice } from '@hooks/useDevice';
import { useContext } from 'react';

import { DeviceTypeContext } from '@store/deviceTypeContext';

import { containerVar, infoVar } from './style.css';

const Info = ({ value }: { value: string }) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
return (
<article>
<ol className={containerVar[deviceType]}>
Expand Down
6 changes: 4 additions & 2 deletions src/views/ApplyPage/components/LinkInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useDevice } from '@hooks/useDevice';
import { useContext } from 'react';

import { DeviceTypeContext } from '@store/deviceTypeContext';

import { containerVar, label, linkVar } from './style.css';

const LinkInput = ({ urls }: { urls: string[] }) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
return (
<>
{urls.length === 1 && (
Expand Down
5 changes: 3 additions & 2 deletions src/views/ApplyPage/components/PartSection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useContext } from 'react';
import { useFormContext } from 'react-hook-form';

import SelectBox from '@components/Select';
import Textarea from '@components/Textarea';
import { useDevice } from '@hooks/useDevice';
import { DeviceTypeContext } from '@store/deviceTypeContext';
import { sectionContainerVar, sectionTitleVar } from 'views/ApplyPage/style.css';
import { Answers, Questions } from 'views/ApplyPage/types';

Expand Down Expand Up @@ -31,7 +32,7 @@ const PartSection = ({
partQuestionsDraft,
questionTypes,
}: PartSectionProps) => {
const deviceType = useDevice();
const { deviceType } = useContext(DeviceTypeContext);
const { getValues } = useFormContext();

const partOptions = questionTypes?.sort((a, b) => a.id - b.id).map(({ typeKr }) => typeKr);
Expand Down
Loading

0 comments on commit a8d5111

Please sign in to comment.