From 5f3ef71e43cab1787aa7a5f127f83e9f80c9e878 Mon Sep 17 00:00:00 2001 From: M Fahru Date: Tue, 7 Feb 2023 10:10:21 -0700 Subject: [PATCH] Implement 'Add Affiliation' UI on the mobile version of the new react dashboard (#11606) * Refactor & change `add-affiliation.tsx` file: * Change class from `user-profile` to `add-affiliation` * Add new optional `className` props for custom styling * Show affiliation widget on mobile screen: * Fix bug on use add affiliation hooks: return type should be `boolean`, not `boolean | 0` GitOrigin-RevId: 800b951e2a012797266b1780993b4ed9a918d565 --- .../web/app/views/project/list/side-bar.pug | 2 +- .../{sidebar => }/add-affiliation.tsx | 23 +++++++++++++------ .../components/new-project-button.tsx | 12 ++++++++++ .../components/project-list-root.tsx | 1 + .../components/sidebar/sidebar.tsx | 2 +- .../project-list/add-affiliation.stories.tsx | 2 +- .../stylesheets/app/project-list.less | 10 +++++++- .../components/new-project-button.test.tsx | 12 +++++++--- .../sidebar/add-affiliation.test.tsx | 6 +++-- 9 files changed, 54 insertions(+), 16 deletions(-) rename services/web/frontend/js/features/project-list/components/{sidebar => }/add-affiliation.tsx (55%) diff --git a/services/web/app/views/project/list/side-bar.pug b/services/web/app/views/project/list/side-bar.pug index be7b5e9ab7..6bcda818c4 100644 --- a/services/web/app/views/project/list/side-bar.pug +++ b/services/web/app/views/project/list/side-bar.pug @@ -127,7 +127,7 @@ if (isOverleaf) .row-spaced#userProfileInformation(ng-if="hasProjects") div(ng-hide="withAffiliations", ng-cloak) hr - .text-centered.user-profile + .text-centered.add-affiliation p Are you affiliated with an institution? a.btn.btn-secondary-info.btn-secondary( diff --git a/services/web/frontend/js/features/project-list/components/sidebar/add-affiliation.tsx b/services/web/frontend/js/features/project-list/components/add-affiliation.tsx similarity index 55% rename from services/web/frontend/js/features/project-list/components/sidebar/add-affiliation.tsx rename to services/web/frontend/js/features/project-list/components/add-affiliation.tsx index 51711df5bb..29c50da9e6 100644 --- a/services/web/frontend/js/features/project-list/components/sidebar/add-affiliation.tsx +++ b/services/web/frontend/js/features/project-list/components/add-affiliation.tsx @@ -1,19 +1,26 @@ import { useTranslation } from 'react-i18next' import { Button } from 'react-bootstrap' -import { useProjectListContext } from '../../context/project-list-context' -import getMeta from '../../../../utils/meta' -import { Affiliation } from '../../../../../../types/affiliation' -import { ExposedSettings } from '../../../../../../types/exposed-settings' +import { useProjectListContext } from '../context/project-list-context' +import getMeta from '../../../utils/meta' +import { Affiliation } from '../../../../../types/affiliation' +import { ExposedSettings } from '../../../../../types/exposed-settings' +import classNames from 'classnames' export function useAddAffiliation() { const { totalProjectsCount } = useProjectListContext() const { isOverleaf } = getMeta('ol-ExposedSettings') as ExposedSettings const userAffiliations = getMeta('ol-userAffiliations', []) as Affiliation[] - return { show: isOverleaf && totalProjectsCount && !userAffiliations.length } + return { + show: isOverleaf && totalProjectsCount > 0 && !userAffiliations.length, + } } -function AddAffiliation() { +type AddAffiliationProps = { + className?: string +} + +function AddAffiliation({ className }: AddAffiliationProps) { const { t } = useTranslation() const { show } = useAddAffiliation() @@ -21,8 +28,10 @@ function AddAffiliation() { return null } + const classes = classNames('text-centered', 'add-affiliation', className) + return ( -
+

{t('are_you_affiliated_with_an_institution')}