Skip to content
Snippets Groups Projects
Commit 04ad2ec9 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

accept ToS

parent b565bc80
No related branches found
No related tags found
2 merge requests!264Resolve "add support for matomo",!256Resolve "ToS is missing"
...@@ -30,6 +30,7 @@ export const ModalLayout = ({ children }: ModalLayoutProps): JSX.Element => { ...@@ -30,6 +30,7 @@ export const ModalLayout = ({ children }: ModalLayoutProps): JSX.Element => {
modalName === 'login' && 'h-auto w-[400px]', modalName === 'login' && 'h-auto w-[400px]',
modalName === 'access-denied' && 'h-auto w-[400px]', modalName === 'access-denied' && 'h-auto w-[400px]',
modalName === 'select-project' && 'h-auto w-[400px]', modalName === 'select-project' && 'h-auto w-[400px]',
modalName === 'terms-of-service' && 'h-auto w-[400px]',
modalName === 'add-comment' && 'h-auto w-[400px]', modalName === 'add-comment' && 'h-auto w-[400px]',
modalName === 'error-report' && 'h-auto w-[800px]', modalName === 'error-report' && 'h-auto w-[800px]',
['edit-overlay', 'logged-in-menu'].includes(modalName) && 'h-auto w-[432px]', ['edit-overlay', 'logged-in-menu'].includes(modalName) && 'h-auto w-[432px]',
...@@ -46,7 +47,7 @@ export const ModalLayout = ({ children }: ModalLayoutProps): JSX.Element => { ...@@ -46,7 +47,7 @@ export const ModalLayout = ({ children }: ModalLayoutProps): JSX.Element => {
<div> {modalTitle} </div> <div> {modalTitle} </div>
)} )}
{modalName !== 'logged-in-menu' && ( {modalName !== 'logged-in-menu' && modalName !== 'terms-of-service' && (
<button type="button" onClick={handleCloseModal} aria-label="close button"> <button type="button" onClick={handleCloseModal} aria-label="close button">
<Icon name="close" className="fill-font-500" /> <Icon name="close" className="fill-font-500" />
</button> </button>
......
...@@ -2,22 +2,43 @@ import React from 'react'; ...@@ -2,22 +2,43 @@ import React from 'react';
import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { Button } from '@/shared/Button'; import { Button } from '@/shared/Button';
import { logout } from '@/redux/user/user.thunks'; import { getSessionValid, logout, updateUser } from '@/redux/user/user.thunks';
import { closeModal } from '@/redux/modal/modal.slice';
import { userSelector } from '@/redux/user/user.selectors';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { termsOfServiceValSelector } from '@/redux/configuration/configuration.selectors';
export const ToSModal: React.FC = () => { export const ToSModal: React.FC = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { userData } = useAppSelector(userSelector);
const termsOfService = useAppSelector(termsOfServiceValSelector);
const updateUserTosHandler = async (): Promise<void> => { const updateUserTosHandler = async (): Promise<void> => {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('update'); console.log('update');
if (userData) {
const user = { ...userData, termsOfUseConsent: true };
await dispatch(updateUser(user));
await dispatch(getSessionValid());
dispatch(closeModal());
}
}; };
const logoutHandler = (): void => { const logoutHandler = async (): Promise<void> => {
dispatch(logout()); await dispatch(logout());
dispatch(closeModal());
}; };
return ( return (
<div className="w-[400px] border border-t-[#E1E0E6] bg-white p-[24px]"> <div className="w-[400px] border border-t-[#E1E0E6] bg-white p-[24px]">
<div className="grid grid-cols-2 gap-2"> <div>
I agree to the minerva{' '}
<a href={termsOfService} target="_blank" className="underline">
Terms of Service.
</a>
</div>
<div className="mt-4 grid grid-cols-2 gap-2">
<div> <div>
<Button <Button
className="ring-transparent hover:ring-transparent" className="ring-transparent hover:ring-transparent"
......
...@@ -102,6 +102,7 @@ export const apiPath = { ...@@ -102,6 +102,7 @@ export const apiPath = {
getSubmapConnections: (): string => `projects/${PROJECT_ID}/submapConnections/`, getSubmapConnections: (): string => `projects/${PROJECT_ID}/submapConnections/`,
logout: (): string => `doLogout`, logout: (): string => `doLogout`,
user: (login: string): string => `users/${login}`, user: (login: string): string => `users/${login}`,
updateUser: (login: string): string => `users/${login}`,
getStacktrace: (code: string): string => `stacktrace/${code}`, getStacktrace: (code: string): string => `stacktrace/${code}`,
submitError: (): string => `minervanet/submitError`, submitError: (): string => `minervanet/submitError`,
getOauthProviders: (): string => `oauth/providers/`, getOauthProviders: (): string => `oauth/providers/`,
......
...@@ -9,9 +9,11 @@ import { getError } from '@/utils/error-report/getError'; ...@@ -9,9 +9,11 @@ import { getError } from '@/utils/error-report/getError';
import axios, { HttpStatusCode } from 'axios'; import axios, { HttpStatusCode } from 'axios';
import { showToast } from '@/utils/showToast'; import { showToast } from '@/utils/showToast';
import { setLoginForOldMinerva } from '@/utils/setLoginForOldMinerva'; import { setLoginForOldMinerva } from '@/utils/setLoginForOldMinerva';
import { apiPath } from '../apiPath'; import { ThunkConfig } from '@/types/store';
import { closeModal, openLoggedInMenuModal } from '../modal/modal.slice'; import { userSchema } from '@/models/userSchema';
import { hasPrivilege } from './user.utils'; import { hasPrivilege } from './user.utils';
import { closeModal, openLoggedInMenuModal } from '../modal/modal.slice';
import { apiPath } from '../apiPath';
const getUserRole = (privileges: UserPrivilege[]): string => { const getUserRole = (privileges: UserPrivilege[]): string => {
if (hasPrivilege(privileges, 'IS_ADMIN')) { if (hasPrivilege(privileges, 'IS_ADMIN')) {
...@@ -118,3 +120,29 @@ export const logout = createAsyncThunk('user/logout', async () => { ...@@ -118,3 +120,29 @@ export const logout = createAsyncThunk('user/logout', async () => {
return Promise.reject(getError({ error, prefix: 'Log out' })); return Promise.reject(getError({ error, prefix: 'Log out' }));
} }
}); });
export const updateUser = createAsyncThunk<undefined, User, ThunkConfig>(
'users/updateUser',
// eslint-disable-next-line consistent-return
async user => {
try {
const newUser = await axiosInstance.patch<User>(
apiPath.updateUser(user.login),
{
user: {
termsOfUseConsent: user.termsOfUseConsent,
},
},
{
withCredentials: true,
},
);
validateDataUsingZodSchema(newUser, userSchema);
showToast({ type: 'success', message: 'ToS agreement registered' });
} catch (error) {
return Promise.reject(getError({ error }));
}
},
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment