From 7aa703b46561386a7ce4025033ea7a5e017b14ff Mon Sep 17 00:00:00 2001 From: Vitalii Kiiko Date: Mon, 7 Oct 2024 15:45:04 +0200 Subject: [PATCH] - fixed typo; - new version of menu topbar; - registration page - added automatic birth date population; --- src/assets/scss/components/topBar.scss | 16 +++++++ .../FormField/components/Table/index.js | 2 +- src/components/TopBarProfileMenu/index.js | 35 ++++++++++++-- .../components/AppTopbar/index.js | 48 +++++++++++++++++++ src/layouts/DefaultLayout/index.js | 40 ++-------------- src/pages/Registration/index.js | 5 +- 6 files changed, 104 insertions(+), 42 deletions(-) create mode 100644 src/layouts/DefaultLayout/components/AppTopbar/index.js diff --git a/src/assets/scss/components/topBar.scss b/src/assets/scss/components/topBar.scss index 4378537..d4bf4c7 100644 --- a/src/assets/scss/components/topBar.scss +++ b/src/assets/scss/components/topBar.scss @@ -46,4 +46,20 @@ .p-menu-separator { border-color: var(--menu-borderColor); } +} + +.topBar__menuCompanyItem { + margin: 0; + padding: 0.55rem 1rem 0.75rem 1rem; + border-top-right-radius: 0; + border-top-left-radius: 0; + display: block; + + &[data-active="true"] { + color: var(--primary-text); + } + + i { + margin-right: 7px; + } } \ No newline at end of file diff --git a/src/components/FormField/components/Table/index.js b/src/components/FormField/components/Table/index.js index a35bffa..0fffbee 100644 --- a/src/components/FormField/components/Table/index.js +++ b/src/components/FormField/components/Table/index.js @@ -121,7 +121,7 @@ const Table = ({ {!isEmpty(columns) && !shouldDisableNewRows - ?
{__('Aggiungi una righa', 'gepafin')}
+ ?
{__('Aggiungi una riga', 'gepafin')}
: null} ) } diff --git a/src/components/TopBarProfileMenu/index.js b/src/components/TopBarProfileMenu/index.js index 64101c4..526e66c 100644 --- a/src/components/TopBarProfileMenu/index.js +++ b/src/components/TopBarProfileMenu/index.js @@ -1,4 +1,4 @@ -import React, { useRef } from 'react'; +import React, { useState, useEffect } from 'react'; import { __ } from '@wordpress/i18n'; import { useNavigate } from 'react-router-dom'; @@ -7,7 +7,6 @@ import { storeSet, useStore, useTrackedStore } from '../../store'; // components import { Menu } from 'primereact/menu'; -import { Avatar } from 'primereact/avatar'; import { intersection } from 'ramda'; const TopBarProfileMenu = ({ menuLeftRef }) => { @@ -15,7 +14,19 @@ const TopBarProfileMenu = ({ menuLeftRef }) => { const userData = useTrackedStore().main.userData(); const fulleName = `${userData.firstName} ${userData.lastName}`; const permissions = useStore().main.getPermissions(); - + const companies = useStore().main.companies(); + const chosenCompanyId = useStore().main.chosenCompanyId() + const [companyItems, setCompanyItems] = useState([]); + const renderCompanyItem = (item) => ( + { + } : switchCompany(item.companyId)} + data-id={item.companyId} + data-active={chosenCompanyId === item.companyId}> + + {item.label} + + ); let items = [ { template: (item, options) => { @@ -45,6 +56,11 @@ const TopBarProfileMenu = ({ menuLeftRef }) => { }, enable: !intersection(permissions, ['MANAGE_TENDERS']).length }, + { + label: __('Seleziona azienda', 'gepafin'), + items: companyItems, + enable: true + }, { separator: true, enable: true @@ -59,6 +75,19 @@ const TopBarProfileMenu = ({ menuLeftRef }) => { } ].filter(o => o.enable); + const switchCompany = (id) => { + console.log('switchCompany'); + } + + useEffect(() => { + const items = companies.map(o => ({ + label: o.companyName, + companyId: o.id, + template: renderCompanyItem + })); + setCompanyItems(items) + }, [companies]) + return <> diff --git a/src/layouts/DefaultLayout/components/AppTopbar/index.js b/src/layouts/DefaultLayout/components/AppTopbar/index.js new file mode 100644 index 0000000..3627539 --- /dev/null +++ b/src/layouts/DefaultLayout/components/AppTopbar/index.js @@ -0,0 +1,48 @@ +import React, { useRef } from 'react'; +import { __ } from '@wordpress/i18n'; + +// components +import { Toolbar } from 'primereact/toolbar'; +import { Link } from 'react-router-dom'; +import LogoIcon from '../../../../icons/LogoIcon'; +import { IconField } from 'primereact/iconfield'; +import { InputIcon } from 'primereact/inputicon'; +import { InputText } from 'primereact/inputtext'; +import { Badge } from 'primereact/badge'; +import { Button } from 'primereact/button'; +import TopBarProfileMenu from '../../../../components/TopBarProfileMenu'; + +const AppTopbar = () => { + const menuLeft = useRef(null); + + const startContent = + + ; + + const endContent =
+ + + + + + + + + + + + +
+ + return( + + ) +} + +export default AppTopbar; \ No newline at end of file diff --git a/src/layouts/DefaultLayout/index.js b/src/layouts/DefaultLayout/index.js index 429325d..f144a45 100644 --- a/src/layouts/DefaultLayout/index.js +++ b/src/layouts/DefaultLayout/index.js @@ -1,5 +1,4 @@ -import React, { useEffect, useRef } from 'react'; -import { Link } from 'react-router-dom'; +import React, { useEffect } from 'react'; import { __ } from '@wordpress/i18n'; import { useLocation } from 'react-router-dom'; @@ -7,18 +6,10 @@ import { useLocation } from 'react-router-dom'; import { useStore, storeSet } from '../../store'; // components -import { Toolbar } from 'primereact/toolbar'; -import { Button } from 'primereact/button'; -import { IconField } from 'primereact/iconfield'; -import { InputIcon } from 'primereact/inputicon'; -import { InputText } from 'primereact/inputtext'; -import { Badge } from 'primereact/badge'; -import LogoIcon from '../../icons/LogoIcon'; -import TopBarProfileMenu from '../../components/TopBarProfileMenu'; import AppSidebar from './components/AppSidebar'; +import AppTopbar from './components/AppTopbar'; const DefaultLayout = ({ children }) => { - const menuLeft = useRef(null); const isError404 = useStore().main.isError404(); const location = useLocation(); @@ -26,34 +17,9 @@ const DefaultLayout = ({ children }) => { storeSet.main.isError404(false); }, [location]); - const startContent = - - ; - - const endContent =
- - - - - - - - - - - - -
- return (
- +
diff --git a/src/pages/Registration/index.js b/src/pages/Registration/index.js index 344c47c..6a103ed 100644 --- a/src/pages/Registration/index.js +++ b/src/pages/Registration/index.js @@ -76,10 +76,12 @@ const Registration = () => { const validateCallback = (data) => { if (data.status === 'SUCCESS') { - const { codiceFiscale, firstName, lastName } = data.data; + const { codiceFiscale, firstName, lastName, dateOfBirth } = data.data; + const dateOfBirthObj = new Date(dateOfBirth); setValue('codiceFiscale', codiceFiscale); setValue('firstName', firstName); setValue('lastName', lastName); + setValue('birthDate', dateOfBirthObj); } else { errorMsgs.current.show([ { @@ -183,6 +185,7 @@ const Registration = () => {