add-affiliation.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { useTranslation } from 'react-i18next'
  2. import { useProjectListContext } from '../context/project-list-context'
  3. import getMeta from '../../../utils/meta'
  4. import classNames from 'classnames'
  5. import OLButton from '@/shared/components/ol/ol-button'
  6. export function useAddAffiliation() {
  7. const { totalProjectsCount } = useProjectListContext()
  8. const { isOverleaf } = getMeta('ol-ExposedSettings')
  9. const userAffiliations = getMeta('ol-userAffiliations') || []
  10. return {
  11. show: isOverleaf && totalProjectsCount > 0 && !userAffiliations.length,
  12. }
  13. }
  14. type AddAffiliationProps = {
  15. className?: string
  16. }
  17. function AddAffiliation({ className }: AddAffiliationProps) {
  18. const { t } = useTranslation()
  19. const { show } = useAddAffiliation()
  20. if (!show) {
  21. return null
  22. }
  23. const classes = classNames('text-center', 'add-affiliation', className)
  24. return (
  25. <div className={classes}>
  26. <p>{t('are_you_affiliated_with_an_institution')}</p>
  27. <OLButton variant="secondary" href="/user/settings">
  28. {t('add_affiliation')}
  29. </OLButton>
  30. </div>
  31. )
  32. }
  33. export default AddAffiliation