Skip to content

dashboard-refactor-texts #134

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 3 additions & 10 deletions src/components/Admin/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,25 @@
DASHBOARD_TITLE_GPS_COORDS,
DASHBOARD_TITLE_INFORMATION,
} from './Dashboard.constants';
import DashboardText from '../DashboardText';
import DashboardPages from '../DashboardPages';

Check warning on line 26 in src/components/Admin/Dashboard/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/Dashboard/index.tsx#L26

Added line #L26 was not covered by tests

const Navigation = loadable(() => import('../../../pages/admin/Navigation'));
const { RangePicker } = DatePicker;

type NoUndefinedRangeValueType<DateType> = [DateType | null, DateType | null] | null;

const Dashboard: React.FC = () => {
const [isTextLoading, setIsTextLoading] = useState<boolean>(false);
const [texts, setTexts] = useState<IText[]>([]);
const [newTexts, setNewTexts] = useState<IText[]>(texts);
const [infoText, setInfoText] = useState<IText>({} as IText);
const [festival, setFestival] = useState<IFestival>({} as IFestival);
const [toggleLoading, setToggleLoading] = useState<{ [x: string]: boolean }>({});

useEffect(() => {
setIsTextLoading(true);
TextService.getAll()
.then(setTexts)
.finally(() => setIsTextLoading(false));
TextService.getByTextType(TextType.info).then(setInfoText);
FestivalService.getLastFestival().then((festival) => {
CookieService.set(CookieService.festivalId, festival.id);
setFestival(festival);
});
}, [newTexts]);
}, []);

Check warning on line 44 in src/components/Admin/Dashboard/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/Dashboard/index.tsx#L44

Added line #L44 was not covered by tests

const updateInformationsVisibility = (checked: boolean): void => {
if (infoText) {
Expand Down Expand Up @@ -121,7 +114,7 @@
<Navigation>
<div className="grid grid-cols-12 gap-2 md:gap-5">
<Card bordered={false} className="rounded-lg col-span-12 lg:col-span-8">
<DashboardText isLoading={isTextLoading} texts={texts} setTexts={setTexts} setNewTexts={setNewTexts} />
<DashboardPages />

Check warning on line 117 in src/components/Admin/Dashboard/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/Dashboard/index.tsx#L117

Added line #L117 was not covered by tests
</Card>
<Card bordered={false} className="rounded-lg col-span-12 lg:col-span-4">
<div className="space-y-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const DashboardPageAssociation : React.FC = () => (
<div>Association</div>
);

export default DashboardPageAssociation;

Check warning on line 7 in src/components/Admin/DashboardPages/DashboardPageAssociation/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/DashboardPages/DashboardPageAssociation/index.tsx#L2-L7

Added lines #L2 - L7 were not covered by tests
24 changes: 24 additions & 0 deletions src/components/Admin/DashboardPages/DashboardPageHome/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useEffect, useState } from 'react';
import DashboardText from '../../DashboardText';
import { IText, TextService } from '../../../../services';

const DashboardPageHome: React.FC = () => {
const [isTextLoading, setIsTextLoading] = useState<boolean>(false);
const [texts, setTexts] = useState<IText[]>([]);
const [newTexts, setNewTexts] = useState<IText[]>(texts);

useEffect(() => {
setIsTextLoading(true);
TextService.getAll()
.then(setTexts)
.finally(() => setIsTextLoading(false));
}, [newTexts]);

return (
<div>
<DashboardText isLoading={isTextLoading} texts={texts} setTexts={setTexts} setNewTexts={setNewTexts}/>
</div>
);
};

export default DashboardPageHome;

Check warning on line 24 in src/components/Admin/DashboardPages/DashboardPageHome/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/DashboardPages/DashboardPageHome/index.tsx#L2-L24

Added lines #L2 - L24 were not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const DashboardPageInformation: React.FC = () => (<div>Information</div>);

export default DashboardPageInformation;

Check warning on line 5 in src/components/Admin/DashboardPages/DashboardPageInformation/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/DashboardPages/DashboardPageInformation/index.tsx#L2-L5

Added lines #L2 - L5 were not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const DashboardPageProgrammation: React.FC = () => (<div>Programmation</div>);

export default DashboardPageProgrammation;

Check warning on line 5 in src/components/Admin/DashboardPages/DashboardPageProgrammation/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/DashboardPages/DashboardPageProgrammation/index.tsx#L2-L5

Added lines #L2 - L5 were not covered by tests
42 changes: 42 additions & 0 deletions src/components/Admin/DashboardPages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import { Tabs, TabsProps } from 'antd';
import { ApartmentOutlined, AppstoreFilled, HomeFilled, InfoCircleFilled } from '@ant-design/icons';
import DashboardPageHome from './DashboardPageHome';
import DashboardPageAssociation from './DashboardPageAssociation';
import DashboardPageProgrammation from './DashboardPageProgrammation';
import DashboardPageInformation from './DashboardPageInformation';

const DashboardPages: React.FC = () => {
const pages: TabsProps['items'] = [
{
key: '1',
label: 'Tout',
icon: <HomeFilled />,
children: <DashboardPageHome />
},
{
key: '2',
label: 'Association',
icon: <ApartmentOutlined />,
children: <DashboardPageAssociation />,
disabled: true,
},
{
key: '3',
label: 'Programmation',
icon: <AppstoreFilled />,
children: <DashboardPageProgrammation />,
disabled: true,
},
{
key: '4',
label: 'Information',
icon: <InfoCircleFilled />,
children: <DashboardPageInformation />,
disabled: true,
}
];
return (<Tabs items={pages} />);
};

export default DashboardPages;

Check warning on line 42 in src/components/Admin/DashboardPages/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Admin/DashboardPages/index.tsx#L2-L42

Added lines #L2 - L42 were not covered by tests
6 changes: 3 additions & 3 deletions src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
});

return (
<footer className="text-black text-center w-full p-2 mt-10">
<footer className="text-black text-center w-full p-2 mt-2">

Check warning on line 33 in src/components/Footer/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Footer/index.tsx#L33

Added line #L33 was not covered by tests
<div className="bg-footer mx-auto w-11/12 rounded py-1 my-5" />
<div className="grid grid-cols-5 xl:grid-cols-6 grid-rows-4">
<div className="col-span-6 lg:col-span-5 row-span-5 text-left flex flex-row flex-wrap justify-evenly overflow-x-auto">
{partners.map((partner, key) => (
<Skeleton key={key} avatar={true} active={true} loading={isPartnerLoading}>
{partner.link.trim() === '' ? (
{partner.link && partner.link.trim() === '' ? (

Check warning on line 39 in src/components/Footer/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Footer/index.tsx#L39

Added line #L39 was not covered by tests
<AdvancedImage
plugins={[lazyload({ threshold: 0.5 })]}
cldImg={cloudinary.image(partner.image)}
alt={partner.name}
className="w-auto h-16 2xl:h-24 object-contain"
/>
) : (
<ExternalLink src={partner.link}>
<ExternalLink src={partner.link || ''}>

Check warning on line 47 in src/components/Footer/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/Footer/index.tsx#L47

Added line #L47 was not covered by tests
<AdvancedImage
plugins={[lazyload({ threshold: 0.5 })]}
cldImg={cloudinary.image(partner.image)}
Expand Down
46 changes: 6 additions & 40 deletions src/pages/admin/Navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
TeamOutlined,
VideoCameraOutlined,
} from '@ant-design/icons';
import { Form, Input, message, Modal } from 'antd';
import { Link, useLocation, useNavigate } from 'react-router-dom';
import React, { useState } from 'react';
import { Form, Input, Modal } from 'antd';
import { Link } from 'react-router-dom';
import React from 'react';

Check warning on line 14 in src/pages/admin/Navigation/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/admin/Navigation/index.tsx#L12-L14

Added lines #L12 - L14 were not covered by tests

import { AxiosError } from 'axios';
import { AuthenticationService, CookieService } from '../../../services';
import { programmationTitle, RouterUrl } from '../../../constants';
import { useNavigationHook } from './useNavigation.hook';

Check warning on line 17 in src/pages/admin/Navigation/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/admin/Navigation/index.tsx#L17

Added line #L17 was not covered by tests

const activatedClassCSS =
'flex items-center py-2 px-6 bg-gray-200 bg-opacity-1 text-gray-700 hover:text-gray-900 rounded-l-full';
Expand All @@ -24,7 +23,7 @@

const adminRoutes = [
{
name: 'Dashboard',
name: 'Pages',

Check warning on line 26 in src/pages/admin/Navigation/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/admin/Navigation/index.tsx#L26

Added line #L26 was not covered by tests
link: RouterUrl.home,
icon: <DashboardOutlined />,
},
Expand Down Expand Up @@ -60,40 +59,7 @@
}

const Navigation: React.FC<NavigationProps> = ({ children }) => {
const [isModalVisible, setIsModalVisible] = useState<boolean>(!AuthenticationService.connectedUserCookie());
const [confirmLoginLoading, setConfirmLoginLoading] = useState<boolean>(false);
const [loginForm] = Form.useForm();
const location = useLocation();
const navigate = useNavigate();

const logout = () => {
AuthenticationService.logout();
navigate(RouterUrl.home);
if (location.pathname === RouterUrl.home) navigate(0);
};

const handleLogin = () => {
setConfirmLoginLoading(true);
loginForm
.validateFields()
.then((values) => {
AuthenticationService.logInAsync(values)
.then((result) => {
setConfirmLoginLoading(false);
setIsModalVisible(false);
CookieService.set(CookieService.authToken, 'true', 60 * 60 * 2); // 2 hours
message.success(`${result.username} connecté`);
})
.catch(async (error: AxiosError) => {
await message.error(error.response?.data as string);
setConfirmLoginLoading(false);
CookieService.set(CookieService.authToken, 'false');
})
.finally(() => loginForm.resetFields());
})
.catch((info) => message.warning('Validation failed: ', info));
};

const { isModalVisible, confirmLoginLoading, loginForm, logout, handleLogin } = useNavigationHook();

Check warning on line 62 in src/pages/admin/Navigation/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/admin/Navigation/index.tsx#L62

Added line #L62 was not covered by tests
return (
<div className="grid grid-cols-12 h-screen">
<div className="col-span-1 sm:col-span-2 md:col-span-2 bg-gray-900">
Expand Down
50 changes: 50 additions & 0 deletions src/pages/admin/Navigation/useNavigation.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useState } from 'react';
import { AuthenticationService, CookieService } from '../../../services';
import { Form, message } from 'antd';
import { useLocation, useNavigate } from 'react-router-dom';
import { RouterUrl } from '../../../constants';
import { AxiosError } from 'axios';

export const useNavigationHook = () => {
const [isModalVisible, setIsModalVisible] = useState<boolean>(!AuthenticationService.connectedUserCookie());
const [confirmLoginLoading, setConfirmLoginLoading] = useState<boolean>(false);
const [loginForm] = Form.useForm();
const location = useLocation();
const navigate = useNavigate();

const logout = () => {
AuthenticationService.logout();
navigate(RouterUrl.home);
if (location.pathname === RouterUrl.home) navigate(0);
};

const handleLogin = () => {
setConfirmLoginLoading(true);
loginForm
.validateFields()
.then((values) => {
AuthenticationService.logInAsync(values)
.then((result) => {
setConfirmLoginLoading(false);
setIsModalVisible(false);
CookieService.set(CookieService.authToken, 'true', 60 * 60 * 2); // 2 hours
message.success(`${result.username} connecté`);
})
.catch(async (error: AxiosError) => {
await message.error(error.response?.data as string);
setConfirmLoginLoading(false);
CookieService.set(CookieService.authToken, 'false');
})
.finally(() => loginForm.resetFields());
})
.catch((info) => message.warning('Validation failed: ', info));
};

return {
isModalVisible,
confirmLoginLoading,
loginForm,
logout,
handleLogin
};
};

Check warning on line 50 in src/pages/admin/Navigation/useNavigation.hook.ts

View check run for this annotation

Codecov / codecov/patch

src/pages/admin/Navigation/useNavigation.hook.ts#L2-L50

Added lines #L2 - L50 were not covered by tests
Loading