-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implement several major in ResultCategoryCard/#87
- Loading branch information
Showing
12 changed files
with
219 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
app/ui/result/result-category-card/result-category-card.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import ResultCategoryCard from './result-category-card'; | ||
import { RESULT_CATEGORY } from '@/app/utils/key/result-category.key'; | ||
|
||
const meta = { | ||
title: 'ui/result/category-card', | ||
component: ResultCategoryCard, | ||
decorators: [(Story) => <Story />], | ||
} as Meta<typeof ResultCategoryCard>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
category: RESULT_CATEGORY.COMMON_CULTURE, | ||
totalCredit: 40, | ||
takenCredit: 30, | ||
completed: false, | ||
}, | ||
}; | ||
|
||
export const CompletedSubMajor: Story = { | ||
args: { | ||
category: RESULT_CATEGORY.SUB_MAJOR, | ||
totalCredit: 40, | ||
takenCredit: 40, | ||
completed: true, | ||
}, | ||
}; | ||
|
||
export const UncompletedDualMajor = { | ||
args: { | ||
category: RESULT_CATEGORY.DUAL_BASIC_ACADEMICAL_CULTURE, | ||
totalCredit: 70, | ||
takenCredit: 40, | ||
completed: false, | ||
}, | ||
}; |
90 changes: 90 additions & 0 deletions
90
app/ui/result/result-category-card/result-category-card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use client'; | ||
import { cn } from '@/app/utils/shadcn/utils'; | ||
|
||
import Book from '@/public/assets/book.svg'; | ||
import Image from 'next/image'; | ||
import useDialog from '@/app/hooks/useDialog'; | ||
import * as React from 'react'; | ||
import { DIALOG_KEY } from '@/app/utils/key/dialog-key.util'; | ||
import Link from 'next/link'; | ||
import { useSetAtom } from 'jotai'; | ||
import { isDialogOpenAtom } from '@/app/store/dialog'; | ||
import Button from '../../view/atom/button/button'; | ||
import PieChart from '../../view/molecule/pie-chart/pie-chart'; | ||
import { RESULT_CATEGORY, RESULT_CATEGORY_KO, ResultCategoryKey } from '@/app/utils/key/result-category.key'; | ||
|
||
interface ResultCategoryCardProps { | ||
category: ResultCategoryKey; | ||
totalCredit: number; | ||
takenCredit: number; | ||
completed?: boolean; | ||
} | ||
|
||
const filterSeveralMajor = (category: ResultCategoryKey) => { | ||
const { DUAL_MANDATORY_MAJOR, DUAL_ELECTIVE_MAJOR, DUAL_BASIC_ACADEMICAL_CULTURE, SUB_MAJOR } = RESULT_CATEGORY; | ||
|
||
switch (category) { | ||
case DUAL_MANDATORY_MAJOR: | ||
case DUAL_ELECTIVE_MAJOR: | ||
case DUAL_BASIC_ACADEMICAL_CULTURE: | ||
return <Button label="복수전공" variant="outlined" size="xs" role="none presentation" />; | ||
case SUB_MAJOR: | ||
return <Button label="부전공" variant="outlined" size="xs" role="none presentation" />; | ||
default: | ||
return <></>; | ||
} | ||
}; | ||
|
||
function ResultCategoryCard({ category, totalCredit, takenCredit }: ResultCategoryCardProps) { | ||
const { toggle } = useDialog(DIALOG_KEY.RESULT_CATEGORY); | ||
const setIsOpenDialog = useSetAtom(isDialogOpenAtom); | ||
|
||
const percentage = Number(((takenCredit / totalCredit) * 100).toFixed(0)); | ||
|
||
function handleClickButton() { | ||
toggle(); | ||
setIsOpenDialog(true); | ||
} | ||
return ( | ||
<div | ||
className={cn('flex flex-col gap-6 zIndex-1 rounded-xl shadow-lg bg-white p-[0.4rem]', 'md:w-80 md:p-[1.8rem]')} | ||
> | ||
<div className="flex justify-between items-center"> | ||
<div className={cn('flex gap-4 font-bold text-sm', 'md:text-xl')}> | ||
<Image src={Book} width={24} height={24} alt="category-img" /> | ||
<h3>{RESULT_CATEGORY_KO[category]}</h3> | ||
</div> | ||
{filterSeveralMajor(category)} | ||
</div> | ||
<div className="m-auto"> | ||
<PieChart percentage={percentage} /> | ||
</div> | ||
<div className={cn('flex text-xs font-medium justify-between items-end', 'md:gap-4 md:text-base md:px-2')}> | ||
<div> | ||
<div className={cn('flex', 'md:gap-2')}> | ||
<span>기준학점</span> | ||
<span className="font-bold">{totalCredit}</span> | ||
</div> | ||
<div className={cn('flex', 'md:gap-2')}> | ||
<span>이수학점</span> | ||
<span className={cn('font-bold', percentage === 100 ? 'text-point-blue' : 'text-etc-red')}> | ||
{takenCredit} | ||
</span> | ||
</div> | ||
</div> | ||
<Link | ||
href={{ | ||
pathname: '/result', | ||
query: { | ||
category: 'COMMON_CULTURE', | ||
}, | ||
}} | ||
> | ||
<Button size="sm" label="과목 확인" onClick={handleClickButton} /> | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default ResultCategoryCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.