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

수정된 디자인시스템 컴포넌트 서비스 코드 반영 (Toggle) #794

Merged
merged 1 commit into from
Feb 18, 2024

Conversation

dladncks1217
Copy link
Member

@dladncks1217 dladncks1217 commented Feb 17, 2024

📄 Summary

수정된 디자인시스템 컴포넌트 소스코드 반영

기존코드 - 특정 훅에 의존적, 명령적인 로직 전개 필요, 불필요한 props drilling 빈번하게 발생.

아래처럼 토글 선택할때마다 useSelect불러와서 상태 값 및 핸들러 각 컴포넌트에 주입, 선택된 값에 따라 명령적으로 UI로직을 전개해야 했음.

const ExpenseListSection = ({ tripId, tripType }: ExpenseListProps) => {
  const isMobile = useRecoilValue(mediaQueryMobileState);

  const { selected: selectedFilter, handleSelectClick: handleFilterSelectClick } = useSelect(
    EXPENSE_LIST_FILTERS.DAY_LOG
  );

  return (
    <section css={containerStyling}>
      <Flex styles={{ justify: isMobile ? 'space-between' : 'flex-end' }}>
        {isMobile && <Heading size="xSmall">경비 상세 정보</Heading>}
        <ToggleGroup css={toggleGroupStyling}>
          <Toggle
            text={EXPENSE_LIST_FILTERS.DAY_LOG}
            toggleId={EXPENSE_LIST_FILTERS.DAY_LOG}
            selectedId={selectedFilter}
            changeSelect={handleFilterSelectClick}
            aria-label="날짜 필터"
          />
          <Toggle
            text={EXPENSE_LIST_FILTERS.CATEGORY}
            toggleId={EXPENSE_LIST_FILTERS.CATEGORY}
            selectedId={selectedFilter}
            changeSelect={handleFilterSelectClick}
            aria-label="카테고리 필터"
          />
        </ToggleGroup>
      </Flex>
      {selectedFilter === EXPENSE_LIST_FILTERS.DAY_LOG ? (
        <ExpenseDates tripId={tripId} tripType={tripType} />
      ) : (
        <ExpenseCategories tripId={tripId} tripType={tripType} />
      )}
    </section>

아래와 같이 컴포넌트가 UI로직만 담을 수 있도록 리팩토링

   <Toggle initialSelect={EXPENSE_LIST_FILTERS.DAY_LOG}>
      <section css={containerStyling}>
        <Flex styles={{ justify: isMobile ? 'space-between' : 'flex-end' }}>
          {isMobile && <Heading size="xSmall">경비 상세 정보</Heading>}
          <Flex css={toggleGroupStyling}>
            <Toggle.List
              text={EXPENSE_LIST_FILTERS.DAY_LOG}
              toggleKey={EXPENSE_LIST_FILTERS.DAY_LOG}
              aria-label="날짜 필터"
            />
            <Toggle.List
              text={EXPENSE_LIST_FILTERS.CATEGORY}
              toggleKey={EXPENSE_LIST_FILTERS.CATEGORY}
              aria-label="카테고리 필터"
            />
          </Flex>
        </Flex>
        <Toggle.Item toggleKey={EXPENSE_LIST_FILTERS.DAY_LOG}>
          <ExpenseDates tripId={tripId} tripType={tripType} />
        </Toggle.Item>
        <Toggle.Item toggleKey={EXPENSE_LIST_FILTERS.CATEGORY}>
          <ExpenseCategories tripId={tripId} tripType={tripType} />
        </Toggle.Item>
      </section>
    </Toggle>

#792

@dladncks1217 dladncks1217 added 🔨 Refactor FE-Service 행록 서비스 프론트엔드 labels Feb 17, 2024
@dladncks1217 dladncks1217 self-assigned this Feb 17, 2024
Copy link
Collaborator

@LJW25 LJW25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

완 벽 한 리 더 슬 링 키

@dladncks1217 dladncks1217 merged commit c9b25f1 into develop Feb 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FE-Service 행록 서비스 프론트엔드 🔨 Refactor
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants