-
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.
Merge pull request #71 from sparcs-kaist/migration@setup-react-query
Refactor Account related components with function component, react-query, and ts
- Loading branch information
Showing
18 changed files
with
369 additions
and
347 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
56 changes: 0 additions & 56 deletions
56
src/components/sections/account/AcademicInfoSubSection.jsx
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/components/sections/account/AcademicInfoSubSection.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,44 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { appBoundClassNames as classNames } from '@/common/boundClassNames'; | ||
import { CONTACT } from '@/common/constants'; | ||
import Attributes from '@/components/Attributes'; | ||
import { useSessionInfo } from '@/queries/account'; | ||
import { useTranslatedString } from '@/hooks/useTranslatedString'; | ||
|
||
const AcademicInfoSubSection = () => { | ||
const { t } = useTranslation(); | ||
const translate = useTranslatedString(); | ||
const { data: user } = useSessionInfo(); | ||
|
||
if (!user) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={classNames('subsection', 'subsection--academic-info')}> | ||
<div className={classNames('title')}>{t('ui.title.academicInformation')}</div> | ||
<Attributes | ||
entries={[ | ||
{ name: t('ui.attribute.studentId'), info: user.student_id }, | ||
{ | ||
name: t('ui.attribute.major'), | ||
info: user.majors.map((d) => translate(d, 'name')).join(', '), | ||
}, | ||
]} | ||
/> | ||
<div className={classNames('caption')}> | ||
{t('ui.message.academicInfoCaptionHead')} | ||
<a | ||
href={`mailto:${CONTACT}`} | ||
className={classNames('text-button')} | ||
data-testid="contact-mail"> | ||
{CONTACT} | ||
</a> | ||
{t('ui.message.academicInfoCaptionTail')} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AcademicInfoSubSection; |
174 changes: 0 additions & 174 deletions
174
src/components/sections/account/FavoriteDepartmentsSubSection.jsx
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
src/components/sections/account/FavoriteDepartmentsSubSection.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,77 @@ | ||
import { FormEventHandler, useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { appBoundClassNames as classNames } from '@/common/boundClassNames'; | ||
import SearchFilter from '@/components/SearchFilter'; | ||
import { | ||
useDepartmentOptions, | ||
useSessionInfo, | ||
useUpdateFavoriteDepartments, | ||
} from '@/queries/account'; | ||
import { useTranslatedString } from '@/hooks/useTranslatedString'; | ||
|
||
const FavoriteDepartmentsSubSection = () => { | ||
const [selectedDepartments, setSelectedDepartments] = useState<Set<string>>(new Set([])); | ||
|
||
const { t } = useTranslation(); | ||
const translate = useTranslatedString(); | ||
const { data: user } = useSessionInfo(); | ||
const { data: departmentOptions } = useDepartmentOptions(); | ||
const { mutate: updateFavoriteDepartments } = useUpdateFavoriteDepartments(); | ||
|
||
useEffect(() => { | ||
if (user) { | ||
setSelectedDepartments(new Set(user.favorite_departments.map((d) => String(d.id)))); | ||
} | ||
}, [user]); | ||
|
||
const handleSubmit: FormEventHandler = (e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
updateFavoriteDepartments({ selectedDepartments }); | ||
}; | ||
|
||
if (!user) { | ||
return null; | ||
} | ||
|
||
// TODO: Change comparison logic | ||
const hasChange = | ||
user.favorite_departments.length !== selectedDepartments.size || | ||
user.favorite_departments.some(({ id }) => !selectedDepartments.has(id.toString())); | ||
|
||
return ( | ||
<div className={classNames('subsection', 'subsection--favorite-department')}> | ||
<div className={classNames('title')}>{t('ui.title.settings')}</div> | ||
{departmentOptions ? ( | ||
<form onSubmit={handleSubmit}> | ||
<SearchFilter | ||
updateCheckedValues={(checkedValues: Set<string>) => | ||
setSelectedDepartments(checkedValues) | ||
} | ||
inputName="department" | ||
titleName={t('ui.search.favoriteDepartment')} | ||
options={departmentOptions.map((d) => [ | ||
String(d.id), | ||
`${translate(d, 'name')} (${d.code})`, | ||
])} | ||
checkedValues={selectedDepartments} | ||
/> | ||
<div className={classNames('buttons')}> | ||
<button | ||
type="submit" | ||
className={classNames('text-button', { 'text-button--disabled': !hasChange })} | ||
disabled={!hasChange}> | ||
{t('ui.button.save')} | ||
</button> | ||
</div> | ||
</form> | ||
) : ( | ||
<span>{t('ui.placeholder.loading')}</span> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default FavoriteDepartmentsSubSection; |
Oops, something went wrong.