Skip to content

Commit

Permalink
feat(studies): SJIP-1134 redirect after login on public page
Browse files Browse the repository at this point in the history
  • Loading branch information
AltefrohneGaelle committed Dec 10, 2024
1 parent 7b87b38 commit 7dcda8f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/components/PublicLayout/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Header = () => {
const { keycloak } = useKeycloak();
const query = useQueryParams();
const navigate = useNavigate();

const [redirectUri, setRedirectUri] = useState<string>();
const [openLoginModal, setOpenLoginModal] = useState(false);
const closeLoginModal = () => setOpenLoginModal(false);

Expand Down Expand Up @@ -73,6 +73,7 @@ const Header = () => {
key="dashboard"
icon={<HomeOutlined />}
onClick={() => {
setRedirectUri(STATIC_ROUTES.DASHBOARD);
trackPublicStudies('Dashboard');
setOpenLoginModal(true);
}}
Expand All @@ -88,6 +89,7 @@ const Header = () => {
key="explore-data"
icon={<FileSearchOutlined />}
onClick={() => {
setRedirectUri(STATIC_ROUTES.DATA_EXPLORATION);
trackPublicStudies('Data Exploration');
setOpenLoginModal(true);
}}
Expand All @@ -99,6 +101,7 @@ const Header = () => {
key="variant-data"
icon={<LineStyleIcon />}
onClick={() => {
setRedirectUri(STATIC_ROUTES.VARIANTS);
trackPublicStudies('Variants');
setOpenLoginModal(true);
}}
Expand All @@ -110,6 +113,7 @@ const Header = () => {
key="analytics-data"
icon={<DotChartOutlined />}
onClick={() => {
setRedirectUri(STATIC_ROUTES.ANALYTICS);
trackPublicStudies('Analysis');
setOpenLoginModal(true);
}}
Expand All @@ -123,6 +127,7 @@ const Header = () => {
key="community"
icon={<TeamOutlined />}
onClick={() => {
setRedirectUri(STATIC_ROUTES.COMMUNITY);
trackPublicStudies('Community');
setOpenLoginModal(true);
}}
Expand Down Expand Up @@ -228,7 +233,9 @@ const Header = () => {
]}
className={style.mainHeader}
/>
{openLoginModal && <LoginModal isOpen={openLoginModal} onClose={closeLoginModal} />}
{openLoginModal && (
<LoginModal isOpen={openLoginModal} onClose={closeLoginModal} redirectUri={redirectUri} />
)}
</>
);
};
Expand Down
5 changes: 3 additions & 2 deletions src/components/PublicLayout/LoginModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ const { Title } = Typography;
type LoginModalProps = {
isOpen: boolean;
onClose: () => void;
redirectUri?: string;
};

const LoginModal = ({ isOpen, onClose }: LoginModalProps) => {
const LoginModal = ({ isOpen, onClose, redirectUri }: LoginModalProps) => {
const { keycloak } = useKeycloak();
const query = useQueryParams();

const handleSignin = async (btnName: string) => {
trackPublicStudies(btnName);
const url = keycloak.createLoginUrl({
redirectUri: `${window.location.origin}/${
query.get(REDIRECT_URI_KEY) || STATIC_ROUTES.STUDIES
redirectUri || query.get(REDIRECT_URI_KEY) || STATIC_ROUTES.STUDIES
}`,
locale: intl.getInitOptions().currentLocale,
});
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useQueryParams.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const useQueryParams = () => {
return new URLSearchParams(window.location.search);
};
const useQueryParams = () => new URLSearchParams(window.location.search);

export default useQueryParams;
export default useQueryParams;
10 changes: 8 additions & 2 deletions src/views/PublicStudies/components/PageContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const { Title } = Typography;
const PageContent = () => {
const [searchValue, setSearchValue] = useState('');
const [openLoginModal, setOpenLoginModal] = useState(false);
const [redirectUri, setRedirectUri] = useState<string>();
const manageLoginModal = (isOpen: boolean) => setOpenLoginModal(isOpen);
const manageRedirectUri = (uri: string) => setRedirectUri(uri);

const { stats, isFetchingStats } = useGlobals();
const { studiesParticipants = [] } = stats || {};
Expand All @@ -43,7 +45,7 @@ const PageContent = () => {
}
};

const defaultColumns = getColumns({ manageLoginModal });
const defaultColumns = getColumns({ manageLoginModal, manageRedirectUri });

return (
<Space direction="vertical" size={16} className={styles.pageContent}>
Expand Down Expand Up @@ -83,7 +85,11 @@ const PageContent = () => {
}
/>
{openLoginModal && (
<LoginModal isOpen={openLoginModal} onClose={() => manageLoginModal(false)} />
<LoginModal
isOpen={openLoginModal}
onClose={() => manageLoginModal(false)}
redirectUri={redirectUri}
/>
)}
</Space>
);
Expand Down
36 changes: 32 additions & 4 deletions src/views/PublicStudies/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DataCategory, hasDataCategory } from 'views/Studies';

import { TABLE_EMPTY_PLACE_HOLDER } from 'common/constants';
import { IStudiesParticipants } from 'services/api/arranger/models';
import { STATIC_ROUTES } from 'utils/routes';

import style from './index.module.css';

Expand All @@ -18,9 +19,13 @@ export const TABLE_ID = 'public-studies';

type ColumnsProps = {
manageLoginModal: (isOpen: boolean) => void;
manageRedirectUri: (uri: string) => void;
};

export const getColumns = ({ manageLoginModal }: ColumnsProps): ProColumnType<any>[] => [
export const getColumns = ({
manageLoginModal,
manageRedirectUri,
}: ColumnsProps): ProColumnType<any>[] => [
{
key: 'is_harmonized',
iconTitle: <AuditOutlined />,
Expand Down Expand Up @@ -58,7 +63,16 @@ export const getColumns = ({ manageLoginModal }: ColumnsProps): ProColumnType<an
key: 'study_code',
title: intl.get('entities.study.code'),
dataIndex: 'study_code',
render: (study_code: string) => <a onClick={() => manageLoginModal(true)}>{study_code}</a>,
render: (study_code: string) => (
<a
onClick={() => {
manageRedirectUri(STATIC_ROUTES.STUDIES);
manageLoginModal(true);
}}
>
{study_code}
</a>
),
},
{
key: 'study_name',
Expand Down Expand Up @@ -147,7 +161,14 @@ export const getColumns = ({ manageLoginModal }: ColumnsProps): ProColumnType<an
const participantCount = record?.participant_count || 0;

return participantCount ? (
<a onClick={() => manageLoginModal(true)}>{numberWithCommas(participantCount)}</a>
<a
onClick={() => {
manageRedirectUri(STATIC_ROUTES.DATA_EXPLORATION_PARTICIPANTS);
manageLoginModal(true);
}}
>
{numberWithCommas(participantCount)}
</a>
) : (
participantCount || TABLE_EMPTY_PLACE_HOLDER
);
Expand All @@ -160,7 +181,14 @@ export const getColumns = ({ manageLoginModal }: ColumnsProps): ProColumnType<an
const fileCount = record?.file_count || 0;

return fileCount ? (
<a onClick={() => manageLoginModal(true)}>{numberWithCommas(fileCount)}</a>
<a
onClick={() => {
manageRedirectUri(STATIC_ROUTES.DATA_EXPLORATION_DATAFILES);
manageLoginModal(true);
}}
>
{numberWithCommas(fileCount)}
</a>
) : (
fileCount || TABLE_EMPTY_PLACE_HOLDER
);
Expand Down

0 comments on commit 7dcda8f

Please sign in to comment.