Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapper frontend login + remove temp auth from React frontend #1903

Merged
merged 27 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bf0bf3c
feat(osm-logo): logo add to mapper
NSUWAL123 Nov 20, 2024
aad8209
feat(login): login store add
NSUWAL123 Nov 20, 2024
36db3ea
fix(layer-switcher): close layer-switcher by default
NSUWAL123 Nov 20, 2024
5c15753
feat(login): login dialog popup add
NSUWAL123 Nov 20, 2024
ee8c818
fix(login): util functions add for login
NSUWAL123 Nov 20, 2024
37e1afb
fix(login): store current path on localStorage
NSUWAL123 Nov 20, 2024
b0ee2bf
fix(osmAuth): if user request redirection to mapper frontend then tre…
NSUWAL123 Nov 20, 2024
7af73f8
feat(logo): hot logo add
NSUWAL123 Nov 20, 2024
bd07a72
fix(header): header component ui slice
NSUWAL123 Nov 20, 2024
02aae8a
feat(login): toggle modal state add
NSUWAL123 Nov 20, 2024
683f737
fix(layout): replace hot-header with custom header component
NSUWAL123 Nov 20, 2024
788f7e8
fix(login): replace modalOpen state on parent with stores
NSUWAL123 Nov 20, 2024
67c3071
fix(+layout): barlow font add to root
NSUWAL123 Nov 21, 2024
b35f8da
feat(header): display username and profile image if user logged in
NSUWAL123 Nov 21, 2024
a8758a9
fix(login): signOut add
NSUWAL123 Nov 21, 2024
6201053
feat(drawerItems): drawer menu items add
NSUWAL123 Nov 21, 2024
7cd63ad
feat(header): drawer comp add, signout func add
NSUWAL123 Nov 21, 2024
ed25d68
fix(layerSwitchMenu): width & height fix
NSUWAL123 Nov 21, 2024
0908658
fix(mapLegends): fix(mapLegends): show map legend in dropdown
NSUWAL123 Nov 21, 2024
0557d67
fix(mapControlComponent): add mapLegend to mapControlComponent
NSUWAL123 Nov 21, 2024
9a5de99
fix(projectDetailsV2): remove showing map legend on accordion, btn li…
NSUWAL123 Nov 21, 2024
fc91a5e
remove(login): remove temporary login from react frontend
NSUWAL123 Nov 21, 2024
71cec9c
test: persist osm login across playwright tests (temp login removed) …
spwoodcock Nov 27, 2024
defa9b2
test: fix mapper flow tests, first open page, then click card
spwoodcock Nov 27, 2024
0d8d916
test: disable firefox and webkit tests entirely for now
spwoodcock Nov 27, 2024
9d4b8be
docs: add note about attempting test auth with webkit
spwoodcock Nov 27, 2024
13801d1
test: use btnTestId prop to identify specific button during tests
spwoodcock Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions src/frontend/src/api/Login.ts

This file was deleted.

20 changes: 3 additions & 17 deletions src/frontend/src/components/LoginPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React, { useEffect } from 'react';
import React from 'react';
import CoreModules from '@/shared/CoreModules';
import { Modal } from '@/components/common/Modal';
import { useDispatch } from 'react-redux';
import { useLocation, useNavigate } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { LoginActions } from '@/store/slices/LoginSlice';
import { osmLoginRedirect } from '@/utilfunctions/login';
import { TemporaryLoginService } from '@/api/Login';
import AssetModules from '@/shared/AssetModules';
import OSMImg from '@/assets/images/osm-logo.png';

type loginOptionsType = {
Expand All @@ -24,17 +22,10 @@ const loginOptions: loginOptionsType[] = [
image: OSMImg,
description: 'Edits made in FMTM will be credited to your OSM account.',
},
{
id: 'temp_account',
name: 'Temporary Account',
icon: <AssetModules.PersonIcon color="" sx={{ fontSize: '40px' }} className="fmtm-w-10 fmtm-h-10" />,
description: "If you're not an OSM user or prefer not to create an OSM account.",
},
];

const LoginPopup = () => {
const dispatch = useDispatch();
const navigate = useNavigate();
const location = useLocation();
const from = location.state?.from || '/';

Expand All @@ -44,18 +35,13 @@ const LoginPopup = () => {
if (selectedOption === 'osm_account') {
localStorage.setItem('requestedPath', from);
osmLoginRedirect();
} else {
await dispatch(TemporaryLoginService(`${import.meta.env.VITE_API_URL}/auth/temp-login`, from));
dispatch(LoginActions.setLoginModalOpen(false));
navigate(from);
}
};

const LoginDescription = () => {
return (
<div className="fmtm-flex fmtm-items-start fmtm-flex-col">
<div className="fmtm-text-2xl fmtm-font-bold fmtm-mb-1">Sign In</div>
<div className="fmtm-text-base fmtm-mb-5 fmtm-text-gray-700">Select an account type to sign in</div>
<div className="fmtm-text-2xl fmtm-font-bold fmtm-mb-4">Sign In</div>
<div className="fmtm-w-full fmtm-flex fmtm-flex-col fmtm-gap-4 fmtm-justify-items-center">
{loginOptions?.map((option) => (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const LayerSwitchMenu = ({ map, pmTileLayerData = null }: { map: any; pmTileLaye
backgroundImage: activeLayer === 'None' ? 'none' : `url(${layerIcons[activeLayer] || satelliteImg})`,
backgroundColor: 'white',
}}
className={`fmtm-relative fmtm-group fmtm-order-4 fmtm-w-10 fmtm-h-10 fmtm-border-[1px] fmtm-border-primaryRed hover:fmtm-border-[2px] fmtm-duration-75 fmtm-cursor-pointer fmtm-bg-contain fmtm-rounded-full ${
className={`fmtm-relative fmtm-group fmtm-order-4 fmtm-w-9 fmtm-h-9 fmtm-border-[1px] fmtm-border-primaryRed hover:fmtm-border-[2px] fmtm-duration-75 fmtm-cursor-pointer fmtm-bg-contain fmtm-rounded-full ${
activeLayer === 'None' ? '!fmtm-border-primaryRed' : ''
}`}
></div>
Expand Down
42 changes: 35 additions & 7 deletions src/frontend/src/components/MapLegends.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import React from 'react';
import AssetModules from '@/shared/AssetModules';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuTrigger,
DropdownMenuPortal,
} from '@/components/common/Dropdown';
import { Tooltip } from '@mui/material';

type mapDetialsType = {
value: string;
Expand Down Expand Up @@ -66,13 +73,34 @@ const MapLegends = ({ defaultTheme }: { defaultTheme: any }) => {
};

return (
<div className="fmtm-py-3">
<div className="fmtm-flex fmtm-flex-col fmtm-gap-2">
{MapDetails.map((data, index) => {
return <LegendListItem data={data} key={index} />;
})}
</div>
</div>
<DropdownMenu modal={false}>
<DropdownMenuTrigger className="fmtm-outline-none">
<Tooltip title="Legend Toggle" placement="left">
<div
className={`fmtm-bg-white fmtm-rounded-full hover:fmtm-bg-gray-100 fmtm-cursor-pointer fmtm-duration-300 fmtm-w-9 fmtm-h-9 fmtm-min-h-9 fmtm-min-w-9 fmtm-max-w-9 fmtm-max-h-9 fmtm-flex fmtm-justify-center fmtm-items-center `}
>
<AssetModules.LegendToggleIcon />
</div>
</Tooltip>
</DropdownMenuTrigger>
<DropdownMenuPortal>
<DropdownMenuContent
className="fmtm-px-2 fmtm-border-none fmtm-z-[60px] fmtm-bg-white"
align="end"
alignOffset={100}
sideOffset={-42}
>
<div className="fmtm-py-3">
<p className="fmtm-mb-3">Legend</p>
<div className="fmtm-flex fmtm-flex-col fmtm-gap-2">
{MapDetails.map((data, index) => {
return <LegendListItem data={data} key={index} />;
})}
</div>
</div>{' '}
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenu>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ProjectOptions from '@/components/ProjectDetailsV2/ProjectOptions';
import useOutsideClick from '@/hooks/useOutsideClick';
import LayerSwitchMenu from '../MapComponent/OpenLayersComponent/LayerSwitcher/LayerSwitchMenu';
import { Tooltip } from '@mui/material';
import MapLegends from '@/components/MapLegends';

type mapControlComponentType = {
map: any;
Expand Down Expand Up @@ -45,6 +46,7 @@ const MapControlComponent = ({ map, projectName, pmTileLayerData }: mapControlCo
const dispatch = CoreModules.useAppDispatch();
const [toggleCurrentLoc, setToggleCurrentLoc] = useState(false);
const geolocationStatus = useAppSelector((state) => state.project.geolocationStatus);
const defaultTheme = useAppSelector((state) => state.theme.hotTheme);
const [divRef, toggle, handleToggle] = useOutsideClick();

const handleOnClick = (btnId) => {
Expand Down Expand Up @@ -88,13 +90,14 @@ const MapControlComponent = ({ map, projectName, pmTileLayerData }: mapControlCo
</Tooltip>
))}
<LayerSwitchMenu map={map} pmTileLayerData={pmTileLayerData} />
{/* download options */}
<div
className={`fmtm-relative ${!pathname.includes('project/') ? 'fmtm-hidden' : 'sm:fmtm-hidden'}`}
ref={divRef}
>
<div
onClick={() => handleToggle()}
className="fmtm-bg-white fmtm-rounded-full fmtm-p-2 hover:fmtm-bg-gray-100 fmtm-cursor-pointer fmtm-duration-300 "
className="fmtm-bg-white fmtm-rounded-full hover:fmtm-bg-gray-100 fmtm-cursor-pointer fmtm-duration-300 fmtm-w-9 fmtm-h-9 fmtm-min-h-9 fmtm-min-w-9 fmtm-max-w-9 fmtm-max-h-9 fmtm-flex fmtm-justify-center fmtm-items-center"
>
<AssetModules.FileDownloadIcon />
</div>
Expand All @@ -108,6 +111,7 @@ const MapControlComponent = ({ map, projectName, pmTileLayerData }: mapControlCo
<ProjectOptions projectName={projectName} />
</div>
</div>
<MapLegends defaultTheme={defaultTheme} />
</div>
);
};
Expand Down
9 changes: 7 additions & 2 deletions src/frontend/src/views/OsmAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ function OsmAuth() {
dispatch(LoginActions.setLoginModalOpen(false));

if (requestedPath) {
navigate(`${requestedPath}`);
localStorage.removeItem('requestedPath');
if (requestedPath.includes('mapnow')) {
// redirect to mapper frontend (navigate doesn't work as it's on svelte)
window.location.href = `${window.location.origin}${requestedPath}`;
} else {
navigate(`${requestedPath}`);
localStorage.removeItem('requestedPath');
}
}
};
loginRedirect();
Expand Down
32 changes: 11 additions & 21 deletions src/frontend/src/views/ProjectDetailsV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import MapControlComponent from '@/components/ProjectDetailsV2/MapControlCompone
import { VectorLayer } from '@/components/MapComponent/OpenLayersComponent/Layers';
import { geojsonObjectModel } from '@/constants/geojsonObjectModal';
import getTaskStatusStyle, { getFeatureStatusStyle } from '@/utilfunctions/getTaskStatusStyle';
import MapLegends from '@/components/MapLegends';
import Accordion from '@/components/common/Accordion';
import AsyncPopup from '@/components/MapComponent/OpenLayersComponent/AsyncPopup/AsyncPopup';
import Button from '@/components/common/Button';
import ProjectInfo from '@/components/ProjectDetailsV2/ProjectInfo';
Expand All @@ -41,7 +39,6 @@ import DebugConsole from '@/utilities/DebugConsole';
import { CustomCheckbox } from '@/components/common/Checkbox';
import useDocumentTitle from '@/utilfunctions/useDocumentTitle';
import QrcodeComponent from '@/components/QrcodeComponent';
import { createDropdownMenuScope } from '@radix-ui/react-dropdown-menu';

const ProjectDetailsV2 = () => {
useDocumentTitle('Project Details');
Expand All @@ -50,9 +47,7 @@ const ProjectDetailsV2 = () => {
const navigate = useNavigate();
const { windowSize } = WindowDimension();
const [divRef, toggle, handleToggle] = useOutsideClick();
const [legendRef, legendToggle, handleLegendToggle] = useOutsideClick();

const [mainView, setView] = useState<any>();
const [selectedTaskArea, setSelectedTaskArea] = useState<Record<string, any> | null>(null);
const [selectedTaskFeature, setSelectedTaskFeature] = useState();
const [dataExtractUrl, setDataExtractUrl] = useState<string | undefined>();
Expand Down Expand Up @@ -511,30 +506,25 @@ const ProjectDetailsV2 = () => {
className="fmtm-w-[235px]"
/>
<div className="fmtm-absolute fmtm-bottom-20 sm:fmtm-bottom-3 fmtm-left-3 fmtm-z-50 fmtm-rounded-lg">
<Accordion
ref={legendRef}
body={<MapLegends defaultTheme={defaultTheme} />}
header={
<div className="fmtm-flex fmtm-items-center fmtm-gap-1 sm:fmtm-gap-2">
<p className="fmtm-text-base fmtm-font-normal">LEGEND</p>
</div>
}
onToggle={() => {
handleLegendToggle();
<Button
btnText="BASEMAPS"
icon={<AssetModules.BoltIcon className="!fmtm-text-xl" />}
onClick={() => {
dispatch(ProjectActions.ToggleGenerateMbTilesModalStatus(true));
}}
className="fmtm-py-0 !fmtm-pb-0 fmtm-rounded-lg hover:fmtm-bg-gray-50"
collapsed={!legendToggle}
btnType="other"
className="!fmtm-text-sm !fmtm-pr-2 fmtm-bg-white"
/>
</div>
<div className="fmtm-absolute fmtm-bottom-20 sm:fmtm-bottom-5 fmtm-right-3 fmtm-z-50 fmtm-h-fit">
<Button
btnText="Basemaps"
icon={<AssetModules.BoltIcon />}
btnText="START MAPPING"
icon={<AssetModules.LocationOnIcon className="!fmtm-text-xl" />}
onClick={() => {
dispatch(ProjectActions.ToggleGenerateMbTilesModalStatus(true));
window.location.href = `${window.location.origin}/mapnow/${projectId}`;
}}
btnType="primary"
className="!fmtm-text-base !fmtm-pr-2"
className="!fmtm-text-sm !fmtm-pr-2"
/>
</div>
<div className="fmtm-absolute fmtm-right-0 fmtm-top-0 fmtm-z-50 fmtm-hidden sm:fmtm-block">
Expand Down
1 change: 1 addition & 0 deletions src/mapper/src/assets/images/hot-logo-text.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/mapper/src/assets/images/hot-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/mapper/src/assets/images/osm-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/mapper/src/constants/drawerItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type drawerItemsType = {
name: string;
path: string;
};

export const drawerItems: drawerItemsType[] = [
{
name: 'Explore Projects',
path: `${window.location.origin}`,
},
{
name: 'Learn',
path: 'https://hotosm.github.io/fmtm',
},
{
name: 'About',
path: 'https://docs.fmtm.dev/About/',
},
{
name: 'Support',
path: 'https://github.com/hotosm/fmtm/issues/',
},
{
name: 'Download Custom ODK Collect',
path: 'https://github.com/hotosm/odkcollect/releases/download/v2024.2.4-entity-select/ODK-Collect-v2024.2.4-FMTM.apk',
},
];
Loading
Loading