🩹(frontend) fine tuning 2.3.0
- improve medium button style when 2 lines - improve design on Firefox input title - manage title modal without doc title - improve redirect when 401
This commit is contained in:
@@ -99,9 +99,7 @@ test.describe('Doc Header', () => {
|
|||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByText(
|
page.getByText(`Are you sure you want to delete this document ?`),
|
||||||
`Are you sure you want to delete the document "${randomDoc}"?`,
|
|
||||||
),
|
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
|
|
||||||
await page
|
await page
|
||||||
|
|||||||
@@ -365,7 +365,8 @@ input:-webkit-autofill:focus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.c__button--medium {
|
.c__button--medium {
|
||||||
padding: 0.9rem var(--c--theme--spacings--s);
|
height: auto;
|
||||||
|
min-height: var(--c--components--button--medium-height);
|
||||||
}
|
}
|
||||||
|
|
||||||
.c__button--small {
|
.c__button--small {
|
||||||
@@ -551,6 +552,8 @@ input:-webkit-autofill:focus {
|
|||||||
|
|
||||||
.c__modal__close .c__button {
|
.c__modal__close .c__button {
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
|
top: -0.65rem;
|
||||||
|
right: -0.65rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c__modal--full .c__modal__content {
|
.c__modal--full .c__modal__content {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { PropsWithChildren } from 'react';
|
|||||||
import { Box } from '@/components';
|
import { Box } from '@/components';
|
||||||
|
|
||||||
import { useAuth } from '../hooks';
|
import { useAuth } from '../hooks';
|
||||||
|
import { getAuthUrl } from '../utils';
|
||||||
|
|
||||||
export const Auth = ({ children }: PropsWithChildren) => {
|
export const Auth = ({ children }: PropsWithChildren) => {
|
||||||
const { isLoading, pathAllowed, isFetchedAfterMount, authenticated } =
|
const { isLoading, pathAllowed, isFetchedAfterMount, authenticated } =
|
||||||
@@ -19,6 +20,22 @@ export const Auth = ({ children }: PropsWithChildren) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the user is authenticated and wanted initially to access a document,
|
||||||
|
* we redirect to the document page.
|
||||||
|
*/
|
||||||
|
if (authenticated) {
|
||||||
|
const authUrl = getAuthUrl();
|
||||||
|
if (authUrl) {
|
||||||
|
void replace(authUrl);
|
||||||
|
return (
|
||||||
|
<Box $height="100vh" $width="100vw" $align="center" $justify="center">
|
||||||
|
<Loader />
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the user is not authenticated and the path is not allowed, we redirect to the login page.
|
* If the user is not authenticated and the path is not allowed, we redirect to the login page.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ import { useRouter } from 'next/router';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { useAuthQuery } from '../api';
|
import { useAuthQuery } from '../api';
|
||||||
import { getAuthUrl } from '../utils';
|
|
||||||
|
|
||||||
const regexpUrlsAuth = [/\/docs\/$/g, /\/docs$/g, /^\/$/g];
|
const regexpUrlsAuth = [/\/docs\/$/g, /\/docs$/g, /^\/$/g];
|
||||||
|
|
||||||
export const useAuth = () => {
|
export const useAuth = () => {
|
||||||
const { data: user, ...authStates } = useAuthQuery();
|
const { data: user, ...authStates } = useAuthQuery();
|
||||||
const { pathname, replace } = useRouter();
|
const { pathname } = useRouter();
|
||||||
|
|
||||||
const [pathAllowed, setPathAllowed] = useState<boolean>(
|
const [pathAllowed, setPathAllowed] = useState<boolean>(
|
||||||
!regexpUrlsAuth.some((regexp) => !!pathname.match(regexp)),
|
!regexpUrlsAuth.some((regexp) => !!pathname.match(regexp)),
|
||||||
@@ -18,18 +17,6 @@ export const useAuth = () => {
|
|||||||
setPathAllowed(!regexpUrlsAuth.some((regexp) => !!pathname.match(regexp)));
|
setPathAllowed(!regexpUrlsAuth.some((regexp) => !!pathname.match(regexp)));
|
||||||
}, [pathname]);
|
}, [pathname]);
|
||||||
|
|
||||||
// Redirect to the path before login
|
|
||||||
useEffect(() => {
|
|
||||||
if (!user) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const authUrl = getAuthUrl();
|
|
||||||
if (authUrl) {
|
|
||||||
void replace(authUrl);
|
|
||||||
}
|
|
||||||
}, [user, replace]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user,
|
user,
|
||||||
authenticated: !!user && authStates.isSuccess,
|
authenticated: !!user && authStates.isSuccess,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export * from './api/types';
|
export * from './api';
|
||||||
export * from './components';
|
export * from './components';
|
||||||
export * from './hooks';
|
export * from './hooks';
|
||||||
export * from './utils';
|
export * from './utils';
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ const DocTitleInput = ({ doc }: DocTitleProps) => {
|
|||||||
handleTitleSubmit(event.target.textContent || '')
|
handleTitleSubmit(event.target.textContent || '')
|
||||||
}
|
}
|
||||||
$color={colorsTokens()['greyscale-1000']}
|
$color={colorsTokens()['greyscale-1000']}
|
||||||
|
$minHeight="40px"
|
||||||
|
$padding={{ right: 'big' }}
|
||||||
$css={css`
|
$css={css`
|
||||||
&[contenteditable='true']:empty:not(:focus):before {
|
&[contenteditable='true']:empty:not(:focus):before {
|
||||||
content: '${untitledDocument}';
|
content: '${untitledDocument}';
|
||||||
|
|||||||
@@ -87,9 +87,7 @@ export const ModalRemoveDoc = ({ onClose, doc }: ModalRemoveDocProps) => {
|
|||||||
<Box aria-label={t('Content modal to delete document')}>
|
<Box aria-label={t('Content modal to delete document')}>
|
||||||
{!isError && (
|
{!isError && (
|
||||||
<Text $size="sm" $variation="600">
|
<Text $size="sm" $variation="600">
|
||||||
{t('Are you sure you want to delete the document "{{title}}"?', {
|
{t('Are you sure you want to delete this document ?')}
|
||||||
title: doc.title,
|
|
||||||
})}
|
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useRouter } from 'next/router';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { Box, Text, TextErrors } from '@/components';
|
import { Box, Text, TextErrors } from '@/components';
|
||||||
import { setAuthUrl } from '@/features/auth';
|
import { KEY_AUTH, setAuthUrl } from '@/features/auth';
|
||||||
import { DocEditor } from '@/features/docs/doc-editor';
|
import { DocEditor } from '@/features/docs/doc-editor';
|
||||||
import {
|
import {
|
||||||
Doc,
|
Doc,
|
||||||
@@ -110,6 +110,9 @@ const DocPage = ({ id }: DocProps) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error.status === 401) {
|
if (error.status === 401) {
|
||||||
|
void queryClient.resetQueries({
|
||||||
|
queryKey: [KEY_AUTH],
|
||||||
|
});
|
||||||
setAuthUrl();
|
setAuthUrl();
|
||||||
void replace(`/401`);
|
void replace(`/401`);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user