From b5c9690780b09b099299f21b688740c59341bb85 Mon Sep 17 00:00:00 2001 From: Guillermo Grau Date: Fri, 26 Aug 2022 10:36:46 +0200 Subject: [PATCH 01/10] Added yesterday option in date range selector. --- components/common/DateFilter.js | 4 ++++ lib/date.js | 37 ++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/components/common/DateFilter.js b/components/common/DateFilter.js index 8e50e95a..d568a889 100644 --- a/components/common/DateFilter.js +++ b/components/common/DateFilter.js @@ -18,6 +18,10 @@ export const filterOptions = [ ), value: '24hour', }, + { + label: , + value: '-1day', + }, { label: , value: '1week', diff --git a/lib/date.js b/lib/date.js index 6897df21..cae39ce4 100644 --- a/lib/date.js +++ b/lib/date.js @@ -7,6 +7,8 @@ import { addYears, subHours, subDays, + subMonths, + subYears, startOfMinute, startOfHour, startOfDay, @@ -39,7 +41,7 @@ export function getDateRange(value, locale = 'en-US') { const now = new Date(); const dateLocale = getDateLocale(locale); - const match = value.match(/^(?[0-9]+)(?hour|day|week|month|year)$/); + const match = value.match(/^(?[0-9-]+)(?hour|day|week|month|year)$/); if (!match) return; @@ -78,6 +80,39 @@ export function getDateRange(value, locale = 'en-US') { } } + if (+num === -1) { + switch (unit) { + case 'day': + return { + startDate: subDays(startOfDay(now), 1), + endDate: subDays(endOfDay(now), 1), + unit: 'hour', + value, + }; + case 'week': + return { + startDate: subDays(startOfWeek(now, { locale: dateLocale }), 7), + endDate: subDays(endOfWeek(now, { locale: dateLocale }), 1), + unit: 'day', + value, + }; + case 'month': + return { + startDate: subMonths(startOfMonth(now), 1), + endDate: subMonths(endOfMonth(now), 1), + unit: 'day', + value, + }; + case 'year': + return { + startDate: subYears(startOfYear(now), 1), + endDate: subYears(endOfYear(now), 1), + unit: 'month', + value, + }; + } + } + switch (unit) { case 'day': return { From 66c60176c7b588d2d98c2c34c95e286802bd17e0 Mon Sep 17 00:00:00 2001 From: Guillermo Grau Date: Fri, 26 Aug 2022 10:44:47 +0200 Subject: [PATCH 02/10] Add translations for Yesterday date-range option. --- lang/ca-ES.json | 1 + lang/de-DE.json | 1 + lang/en-GB.json | 1 + lang/en-US.json | 1 + lang/es-MX.json | 1 + lang/fr-FR.json | 1 + lang/it-IT.json | 1 + 7 files changed, 7 insertions(+) diff --git a/lang/ca-ES.json b/lang/ca-ES.json index 8ab41de3..dcbada59 100644 --- a/lang/ca-ES.json +++ b/lang/ca-ES.json @@ -62,6 +62,7 @@ "label.username": "Nom d'usuari", "label.view-details": "Veure els detalls", "label.websites": "Llocs web", + "label.yesterday": "Ahir", "message.active-users": "{x} {x, plural, one {visitant actual} other {visitants actuals}}", "message.confirm-delete": "Segur que vols esborrar {target}?", "message.confirm-reset": "Segur que vols restablir les estadístiques de {target}?", diff --git a/lang/de-DE.json b/lang/de-DE.json index 297de6a2..f95f4fc8 100644 --- a/lang/de-DE.json +++ b/lang/de-DE.json @@ -62,6 +62,7 @@ "label.username": "Benutzername", "label.view-details": "Details anzeigen", "label.websites": "Webseiten", + "label.yesterday": "Gestern", "message.active-users": "{x} {x, plural, one {aktiver Besucher} other {aktive Besucher}}", "message.confirm-delete": "Sind Sie sich sicher, {target} zu löschen?", "message.confirm-reset": "Sind Sie sicher, dass Sie die Statistiken von {target} zurücksetzen wollen?", diff --git a/lang/en-GB.json b/lang/en-GB.json index bc253a60..aa5e3ae3 100644 --- a/lang/en-GB.json +++ b/lang/en-GB.json @@ -62,6 +62,7 @@ "label.username": "Username", "label.view-details": "View details", "label.websites": "Websites", + "label.yesterday": "Yesterday", "message.active-users": "{x} current {x, plural, one {visitor} other {visitors}}", "message.confirm-delete": "Are you sure you want to delete {target}?", "message.confirm-reset": "Are you sure you want to reset {target}'s statistics?", diff --git a/lang/en-US.json b/lang/en-US.json index bc253a60..aa5e3ae3 100644 --- a/lang/en-US.json +++ b/lang/en-US.json @@ -62,6 +62,7 @@ "label.username": "Username", "label.view-details": "View details", "label.websites": "Websites", + "label.yesterday": "Yesterday", "message.active-users": "{x} current {x, plural, one {visitor} other {visitors}}", "message.confirm-delete": "Are you sure you want to delete {target}?", "message.confirm-reset": "Are you sure you want to reset {target}'s statistics?", diff --git a/lang/es-MX.json b/lang/es-MX.json index e9b02c1d..ecefd17b 100644 --- a/lang/es-MX.json +++ b/lang/es-MX.json @@ -62,6 +62,7 @@ "label.username": "Nombre de usuario", "label.view-details": "Ver detalles", "label.websites": "Sitios", + "label.yesterday": "Ayer", "message.active-users": "{x} {x, plural, one {activo} other {activos}}", "message.confirm-delete": "¿Estás seguro(a) de querer eliminar {target}?", "message.confirm-reset": "¿Seguro que deseas restablecer las estadísticas de {target}?", diff --git a/lang/fr-FR.json b/lang/fr-FR.json index ca0b7e41..c2eedb27 100644 --- a/lang/fr-FR.json +++ b/lang/fr-FR.json @@ -62,6 +62,7 @@ "label.username": "Nom d'utilisateur", "label.view-details": "Voir les details", "label.websites": "Sites", + "label.yesterday": "Hier", "message.active-users": "{x} {x, plural, one {visiteur} other {visiteurs}} actuellement", "message.confirm-delete": "Êtes-vous sûr de vouloir supprimer {target} ?", "message.confirm-reset": "Êtes-vous sûr de vouloir réinistialiser les statistiques de {target} ?", diff --git a/lang/it-IT.json b/lang/it-IT.json index 4069bb9c..356e226c 100644 --- a/lang/it-IT.json +++ b/lang/it-IT.json @@ -62,6 +62,7 @@ "label.username": "Nome utente", "label.view-details": "Vedi dettagli", "label.websites": "Siti web", + "label.yesterday": "Ieri", "message.active-users": "{x} {x, plural, one {visitatore} other {visitatori}} online", "message.confirm-delete": "Sei sicuro di voler eliminare {target}?", "message.confirm-reset": "Sei sicuro di voler azzerare le statistiche di {target}?", From 166ab61e5d431d4a96dc0727669ab41b427f5712 Mon Sep 17 00:00:00 2001 From: Guillermo Grau Date: Fri, 26 Aug 2022 10:50:48 +0200 Subject: [PATCH 03/10] Updated public language files. --- public/intl/messages/ca-ES.json | 6 ++++++ public/intl/messages/de-DE.json | 6 ++++++ public/intl/messages/en-GB.json | 6 ++++++ public/intl/messages/en-US.json | 6 ++++++ public/intl/messages/es-MX.json | 6 ++++++ public/intl/messages/fr-FR.json | 6 ++++++ public/intl/messages/it-IT.json | 6 ++++++ 7 files changed, 42 insertions(+) diff --git a/public/intl/messages/ca-ES.json b/public/intl/messages/ca-ES.json index af1fbd6d..9b6013e7 100644 --- a/public/intl/messages/ca-ES.json +++ b/public/intl/messages/ca-ES.json @@ -397,6 +397,12 @@ "value": "Llocs web" } ], + "label.yesterday": [ + { + "type": 0, + "value": "Ahir" + } + ], "message.active-users": [ { "type": 1, diff --git a/public/intl/messages/de-DE.json b/public/intl/messages/de-DE.json index 0bc273b6..11464d33 100644 --- a/public/intl/messages/de-DE.json +++ b/public/intl/messages/de-DE.json @@ -397,6 +397,12 @@ "value": "Webseiten" } ], + "label.yesterday": [ + { + "type": 0, + "value": "Gestern" + } + ], "message.active-users": [ { "type": 1, diff --git a/public/intl/messages/en-GB.json b/public/intl/messages/en-GB.json index 721c765a..ecb654d1 100644 --- a/public/intl/messages/en-GB.json +++ b/public/intl/messages/en-GB.json @@ -397,6 +397,12 @@ "value": "Websites" } ], + "label.yesterday": [ + { + "type": 0, + "value": "Yesterday" + } + ], "message.active-users": [ { "type": 1, diff --git a/public/intl/messages/en-US.json b/public/intl/messages/en-US.json index 721c765a..ecb654d1 100644 --- a/public/intl/messages/en-US.json +++ b/public/intl/messages/en-US.json @@ -397,6 +397,12 @@ "value": "Websites" } ], + "label.yesterday": [ + { + "type": 0, + "value": "Yesterday" + } + ], "message.active-users": [ { "type": 1, diff --git a/public/intl/messages/es-MX.json b/public/intl/messages/es-MX.json index 761018ba..d70fb6e7 100644 --- a/public/intl/messages/es-MX.json +++ b/public/intl/messages/es-MX.json @@ -397,6 +397,12 @@ "value": "Sitios" } ], + "label.yesterday": [ + { + "type": 0, + "value": "Ayer" + } + ], "message.active-users": [ { "type": 1, diff --git a/public/intl/messages/fr-FR.json b/public/intl/messages/fr-FR.json index 6ea8623b..dd789878 100644 --- a/public/intl/messages/fr-FR.json +++ b/public/intl/messages/fr-FR.json @@ -389,6 +389,12 @@ "value": "Sites" } ], + "label.yesterday": [ + { + "type": 0, + "value": "Hier" + } + ], "message.active-users": [ { "type": 1, diff --git a/public/intl/messages/it-IT.json b/public/intl/messages/it-IT.json index 5ff6beee..6e061095 100644 --- a/public/intl/messages/it-IT.json +++ b/public/intl/messages/it-IT.json @@ -397,6 +397,12 @@ "value": "Siti web" } ], + "label.yesterday": [ + { + "type": 0, + "value": "Ieri" + } + ], "message.active-users": [ { "type": 1, From b388961b8b322ad530b3426c3d41c9056008139c Mon Sep 17 00:00:00 2001 From: Aidan Marshall <36016925+aidanm1999@users.noreply.github.com> Date: Fri, 26 Aug 2022 17:22:46 +0200 Subject: [PATCH 04/10] Features: - Removes spellcheck for domain entry field - Adds the ability to assign websites to other users if you are an admin --- components/forms/WebsiteEditForm.js | 55 +++++++++++++++++++-- components/forms/WebsiteEditForm.module.css | 5 ++ components/layout/FormLayout.module.css | 3 +- pages/api/website/index.js | 7 +-- styles/index.css | 1 + 5 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 components/forms/WebsiteEditForm.module.css diff --git a/components/forms/WebsiteEditForm.js b/components/forms/WebsiteEditForm.js index 64655d56..80a6dfc0 100644 --- a/components/forms/WebsiteEditForm.js +++ b/components/forms/WebsiteEditForm.js @@ -1,6 +1,6 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { FormattedMessage } from 'react-intl'; -import { Formik, Form, Field } from 'formik'; +import { Formik, Form, Field, useFormikContext } from 'formik'; import Button from 'components/common/Button'; import FormLayout, { FormButtons, @@ -11,10 +11,14 @@ import FormLayout, { import Checkbox from 'components/common/Checkbox'; import { DOMAIN_REGEX } from 'lib/constants'; import useApi from 'hooks/useApi'; +import useFetch from 'hooks/useFetch'; +import useUser from 'hooks/useUser'; +import styles from './WebsiteEditForm.module.css'; const initialValues = { name: '', domain: '', + owner: '', public: false, }; @@ -33,8 +37,45 @@ const validate = ({ name, domain }) => { return errors; }; +const OwnerDropDown = ({ user, accounts }) => { + console.info(styles); + const { setFieldValue, values } = useFormikContext(); + + useEffect(() => { + if (values.user_id != null && values.owner === '') { + setFieldValue('owner', values.user_id.toString()); + } else if (user?.user_id && values.owner === '') { + setFieldValue('owner', user.user_id.toString()); + } + }, [accounts, setFieldValue, user, values]); + + if (user?.is_admin) { + return ( + + +
+ + {accounts?.map(acc => ( + + ))} + + +
+
+ ); + } else { + return null; + } +}; + export default function WebsiteEditForm({ values, onSave, onClose }) { const { post } = useApi(); + const { data: accounts } = useFetch(`/accounts`); + const { user } = useUser(); const [message, setMessage] = useState(); const handleSubmit = async values => { @@ -72,10 +113,18 @@ export default function WebsiteEditForm({ values, onSave, onClose }) {
- +
+