forked from italia/design-comuni-plone-theme
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added validity dates to Alert block (#795)
* fix: condition with has no content * feat: new date schedule for alert block * feat: condition to set visible the alert view * fix: file cleaned * chore: i18n * refact: changes to upgrade the code * refact: class component to function component for View * fix: condition re-thinked * Update src/components/ItaliaTheme/Blocks/Alert/Sidebar.jsx Co-authored-by: Giulia Ghisini <[email protected]> * Update src/components/ItaliaTheme/Blocks/Alert/Sidebar.jsx Co-authored-by: Giulia Ghisini <[email protected]> * Update src/components/ItaliaTheme/Blocks/Alert/Sidebar.jsx Co-authored-by: Giulia Ghisini <[email protected]> * chore: i18n * fix: removed utils * fix: message conditional * fix: removed unnecessary code * chore: i18n * fix: message as default --------- Co-authored-by: Giulia Ghisini <[email protected]>
- Loading branch information
1 parent
824b757
commit 069c248
Showing
11 changed files
with
486 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Plone\n" | ||
"POT-Creation-Date: 2024-09-04T10:35:48.334Z\n" | ||
"POT-Creation-Date: 2024-10-30T13:16:00.707Z\n" | ||
"Last-Translator: Plone i18n <[email protected]>\n" | ||
"Language-Team: Plone i18n <[email protected]>\n" | ||
"MIME-Version: 1.0\n" | ||
|
@@ -731,6 +731,46 @@ msgstr "" | |
msgid "advandedSectionsFilters" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/Blocks/Alert/AlertWrapper | ||
# defaultMessage: Pubblicazione attiva. | ||
msgid "alert_activeDate" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/Blocks/Alert/AlertWrapper | ||
# defaultMessage: Non visibile. C'è un errore sulle date: la data di scadenza è anteriore alla data d'inizio | ||
msgid "alert_errorDate" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/Blocks/Alert/AlertWrapper | ||
# defaultMessage: Non visibile. E' scaduto il {date}. | ||
msgid "alert_expiredDate" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/Blocks/Alert/AlertWrapper | ||
# defaultMessage: Non visibile. Verà pubblicato il {date} | ||
msgid "alert_futureDate" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/Blocks/Alert/AlertWrapper | ||
# defaultMessage: Scadrà il {date} | ||
msgid "alert_willExpire" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/Blocks/Alert/Sidebar | ||
# defaultMessage: Periodo di visualizzazione | ||
msgid "alertblock_dateTitle" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/Blocks/Alert/Sidebar | ||
# defaultMessage: Scadenza | ||
msgid "alertblock_endDate" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/Blocks/Alert/Sidebar | ||
# defaultMessage: Inizio | ||
msgid "alertblock_startDate" | ||
msgstr "" | ||
|
||
#: components/ItaliaTheme/Blocks/IconBlocks/Sidebar | ||
# defaultMessage: Centrare i card | ||
msgid "alignCards" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { Row, Container } from 'design-react-kit/dist/design-react-kit'; | ||
import { defineMessages, useIntl } from 'react-intl'; | ||
|
||
const messages = defineMessages({ | ||
expiredDate: { | ||
id: 'alert_expiredDate', | ||
defaultMessage: "Non visibile. E' scaduto il {date}.", | ||
}, | ||
activeDate: { | ||
id: 'alert_activeDate', | ||
defaultMessage: 'Pubblicazione attiva.', | ||
}, | ||
futureDate: { | ||
id: 'alert_futureDate', | ||
defaultMessage: 'Non visibile. Verà pubblicato il {date}', | ||
}, | ||
errorDate: { | ||
id: 'alert_errorDate', | ||
defaultMessage: | ||
"Non visibile. C'è un errore sulle date: la data di scadenza è anteriore alla data d'inizio", | ||
}, | ||
willExpire: { | ||
id: 'alert_willExpire', | ||
defaultMessage: 'Scadrà il {date}', | ||
}, | ||
}); | ||
|
||
const AlertWrapper = ({ data, children }) => { | ||
const intl = useIntl(); | ||
const userLogged = useSelector((state) => state.userSession.token); | ||
|
||
const isActive = () => { | ||
const today = new Date().getTime(); | ||
const start = data.startDate ? new Date(data.startDate).getTime() : 0; | ||
const end = data.endDate | ||
? new Date(data.endDate).getTime() | ||
: Number.MAX_SAFE_INTEGER; | ||
|
||
const returnValue = { | ||
active: false, | ||
message: intl.formatMessage(messages.expiredDate, { | ||
date: new Date(data.endDate).toLocaleString(), | ||
}), | ||
}; | ||
|
||
if (end < start) { | ||
returnValue.message = intl.formatMessage(messages.errorDate); | ||
} else if (today < start) { | ||
returnValue.message = intl.formatMessage(messages.futureDate, { | ||
date: new Date(data.startDate).toLocaleString(), | ||
}); | ||
} else if (today < end) { | ||
returnValue.message = intl.formatMessage(messages.activeDate); | ||
if (data.endDate) { | ||
returnValue.message += | ||
' ' + | ||
intl.formatMessage(messages.willExpire, { | ||
date: new Date(data.endDate).toLocaleString(), | ||
}); | ||
} | ||
returnValue.active = true; | ||
} | ||
|
||
return returnValue; | ||
}; | ||
|
||
const activeStatus = isActive(); | ||
|
||
return ( | ||
<> | ||
{(userLogged || activeStatus.active) && ( | ||
<> | ||
{userLogged && ( | ||
<Container className="alert-info-dates"> | ||
<Row> | ||
<p className="alert-info-text">{activeStatus.message}</p> | ||
</Row> | ||
</Container> | ||
)} | ||
{children} | ||
</> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default AlertWrapper; |
Oops, something went wrong.