Skip to content

Commit

Permalink
completed recurr. events; improved translations (switch locale at run…
Browse files Browse the repository at this point in the history
…time);
  • Loading branch information
SirChri committed Jun 1, 2023
1 parent d8ef1ff commit 1548e24
Show file tree
Hide file tree
Showing 9 changed files with 25,363 additions and 41 deletions.
25,244 changes: 25,244 additions & 0 deletions client/package-lock.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 3,23 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@fullcalendar/core": "^6.1.7",
"@fullcalendar/daygrid": "^6.1.7",
"@fullcalendar/interaction": "^6.1.7",
"@fullcalendar/react": "^6.1.7",
"@fullcalendar/core": "^6.1.8",
"@fullcalendar/daygrid": "^6.1.8",
"@fullcalendar/interaction": "^6.1.8",
"@fullcalendar/react": "^6.1.8",
"@fullcalendar/rrule": "^6.1.6",
"@fullcalendar/timegrid": "^6.1.7",
"@fullcalendar/timegrid": "^6.1.8",
"@mui/material": "^5.11.12",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"dotenv": "^16.0.3",
"jsonexport": "^3.2.0",
"moment": "^2.29.4",
"ra-data-simple-rest": "^4.8.2",
"react": "^18.2.0",
"react-hook-form": "7.43.9",
"react-admin": "^4.8.2",
"react-hook-form": "7.40.0",
"react-calendar": "^4.2.1",
"react-dom": "^18.2.0",
"rrule": "^2.7.2",
Expand All @@ -30,6 31,7 @@
"xss": "^1.0.14"
},
"devDependencies": {
"@types/jsonexport": "^3.0.2",
"@types/node": "^18.14.6",
"@types/react-calendar": "^3.9.0",
"@types/react-color": "^3.0.6",
Expand Down
2 changes: 1 addition & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 28,7 @@ const i18nProvider = polyglotI18nProvider(locale => {

// Always fallback on english
return englishMessages;
}, 'it');
}, 'en');

const App = () => (
<Admin
Expand Down
9 changes: 8 additions & 1 deletion client/src/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,7 @@ import { Tabs, Tab, Toolbar, AppBar, Box, Typography } from '@mui/material';
import { Link, matchPath, useLocation } from 'react-router-dom';
import { UserMenu, Logout, LoadingIndicator, useTranslate } from 'react-admin';
import BadgeIcon from '@mui/icons-material/Badge';
import { LocalesMenuButton } from 'react-admin';

const Header = () => {
const location = useLocation();
Expand Down Expand Up @@ -55,7 56,7 @@ const Header = () => {
value="/calendar"
/>
<Tab
label={'Summary'}
label={translate(`ess.summary.name`)}
component={Link}
to="/summary"
value="/summary"
Expand All @@ -80,6 81,12 @@ const Header = () => {
</Tabs>
</Box>
<Box display="flex">
<LocalesMenuButton
languages={[
{ locale: 'en', name: 'English' },
{ locale: 'it', name: 'Italiano' },
]}
/>
<LoadingIndicator
sx={{
'& .RaLoadingIndicator-loader': {
Expand Down
21 changes: 20 additions & 1 deletion client/src/i18n/en.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 31,26 @@ const customEnglishMessages: TranslationMessages = {
},
ess: {
calendar: {
name: "Calendar"
name: "Calendar",
event: {
error: "Something went wrong.",
error_create: "Error on event creation",
success_create: "Event created",
error_update: "Error on event update",
success_update: "Event updated",
error_delete: "Error on event delete",
success_delete: "Event removed",
recurring: {
thisev: "This event",
thisandfoll: "This and the following events"
}
},
calendarlist: {
number: "Number"
},
},
summary: {
name: "Report"
}
}
};
Expand Down
23 changes: 21 additions & 2 deletions client/src/i18n/it.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 169,7 @@ const customItalianMessages: TranslationMessages = {
oneOf: 'Deve essere uno di: %{options}',
regex: 'Deve rispettare il formato (espressione regolare): %{pattern}'
},
saved_queries: {
saved_queries: {
label: 'Saved queries',
query_name: 'Query name',
new_label: 'Save current query...',
Expand Down Expand Up @@ -235,7 235,26 @@ saved_queries: {
},
ess: {
calendar: {
name: "Calendario"
name: "Calendario",
event: {
error: "Qualcosa è andato storto.",
error_create: "Errore durante la creazione dell'evento",
success_create: "Evento creato correttamente",
error_update: "Errore durante l'aggiornamento dell'evento",
success_update: "Evento aggiornato correttamente",
error_delete: "Errore durante la cancellazione dell'evento",
success_delete: "Evento eliminato correttamente",
recurring: {
thisev: "Questo evento",
thisandfoll: "Questo e gli eventi futuri"
}
},
calendarlist: {
number: "Matricola"
},
},
summary: {
name: "Report"
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions client/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 83,7 @@ code {
.react-calendar__tile--active {
background: #006edc !important;
color: white;
}
.fc-event {
overflow: hidden;
}
54 changes: 30 additions & 24 deletions client/src/views/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 7,7 @@ import { dataProvider } from '../dataProvider'
import interactionPlugin from '@fullcalendar/interaction';
import Dialog from '@mui/material/Dialog';
import AddIcon from '@mui/icons-material/Add';
import { useNotify, useCreate, useUpdate, useGetList, Loading, useDelete } from 'react-admin';
import { useNotify, useCreate, useUpdate, useGetList, Loading, useDelete, useTranslate, useLocaleState } from 'react-admin';
import Fab from '@mui/material/Fab';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
Expand All @@ -19,7 19,7 @@ import moment from 'moment';
import { EventPopup } from '../components/EventPopup';
import Calendar from 'react-calendar';
import 'react-calendar/dist/Calendar.css';
import { EventContentArg, EventInput } from '@fullcalendar/core';
import { EventChangeArg, EventContentArg, EventInput } from '@fullcalendar/core';
import rrulePlugin from '@fullcalendar/rrule'
import { RRule, RRuleSet } from 'rrule';

Expand All @@ -34,6 34,8 @@ import RepeatRoundedIcon from '@mui/icons-material/RepeatRounded';

export default function CalendarView() {
const isSmall = useMediaQuery<Theme>(theme => theme.breakpoints.down('md'));
const translate = useTranslate();
const [locale] = useLocaleState();
const calendarRef = useRef<FullCalendar>(null);
const [create] = useCreate();
const [update] = useUpdate();
Expand Down Expand Up @@ -229,36 231,36 @@ export default function CalendarView() {
data.customer_id = data.customer_id === "" ? null : data.customer_id;
create('event', { data }, {
onError: (error) => {
notify("Error on creation") //TODO: make locale dynamic
notify(translate("ess.calendar.event.error_create"))
console.error(error)
},
onSettled: (data, error) => {
handleClose();
reloadEvents(() => {
notify("Item succesfully created") //TODO: make locale dynamic
notify(translate("ess.calendar.event.success_create"))
})
},
});
}

const eventEditSubmit = (record: any) => {
const recId = record?.id || editDialog.record;
const eventEditSubmit = (info?: EventChangeArg) => {
const record = info && info.event ? flattenRecord(info.event.toJSON()) : info || editDialog.record;

if (record?._parent) {
setRecurrDialog({
open: true,
record: record,
fcinfo: undefined,
fcinfo: info,
event: "edit"
})
} else {
update('event', { id: recId, data: record }, {
update('event', { id: record.id, data: record }, {
onError: (error) => {
notify("Error on updating") //TODO: make locale dynamic
notify(translate("ess.calendar.event.error_update"))
console.error(error)
},
onSettled: (data, error) => {
notify("Item updated") //TODO: make locale dynamic
notify(translate("ess.calendar.event.success_update"))

shallowEditEvent(record);
}
Expand All @@ -279,10 281,11 @@ export default function CalendarView() {
} else {
_delete('event', { id: record.id, previousData: record }, {
onError: (error) => {
notify("Error on removing") //TODO: make locale dynamic
notify(translate("ess.calendar.event.error_delete"))
console.error(error)
},
onSettled: (data, error) => {
notify(translate("ess.calendar.event.success_delete"))
shallowRemoveEvent(record.id)
setEditDialog({
open: false,
Expand Down Expand Up @@ -344,6 347,8 @@ export default function CalendarView() {

const callback = () => {
reloadEvents(() => {
notify(translate("ess.calendar.event.success_update"))

setRecurrAction("0")
setPopover({
open: false,
Expand Down Expand Up @@ -378,17 383,17 @@ export default function CalendarView() {

update('event', { id: parent.id, data: parent }, {
onError: (error) => {
notify("Error on creation") //TODO: make locale dynamic
notify(translate("ess.calendar.event.error"))
console.error(error)
},
onSettled: (data, error) => {
onSettled: (d, error) => {
if (event == "edit") {
create('event', { data: data }, {
onError: (error) => {
notify("Error on creation") //TODO: make locale dynamic
notify(translate("ess.calendar.event.error"))
console.error(error)
},
onSettled: (data, error) => {
onSettled: (d, error) => {
callback()
}
});
Expand All @@ -411,14 416,14 @@ export default function CalendarView() {

update('event', { id: parent.id, data: parent }, {
onError: (error) => {
notify("Error on creation") //TODO: make locale dynamic
notify(translate("ess.calendar.event.error"))
console.error(error)
},
onSettled: (oldevt, error) => {
if (event == "edit") {
create('event', { data: data }, {
onError: (error) => {
notify("Error on creation") //TODO: make locale dynamic
notify(translate("ess.calendar.event.error"))
console.error(error)
},
onSettled: (data, error) => {
Expand All @@ -439,7 444,7 @@ export default function CalendarView() {

_delete('event', { id: data.id, previousData: parent }, {
onError: (error) => {
notify("Error on removing") //TODO: make locale dynamic
notify(translate("ess.calendar.event.error"))
console.error(error)
},
onSettled: (data, error) => {
Expand Down Expand Up @@ -489,6 494,7 @@ export default function CalendarView() {
showFixedNumberOfWeeks={true}
//onChange={setCalendarValue}
value={calendarValue}
locale={locale}
onClickDay={(value) => {
let calendar = calendarRef.current;
calendar?.getApi().gotoDate(value)
Expand Down Expand Up @@ -527,7 533,7 @@ export default function CalendarView() {
<ListItemText
id={labelId}
primary={record.fullname}
secondary={"Matricola: " record.number} />
secondary={translate("ess.calendar.calendarlist.number") ": " record.number} />
</ListItemButton>
</ListItem>
)
Expand All @@ -546,7 552,7 @@ export default function CalendarView() {
<Box width={isSmall ? 'auto' : 'calc(100% - 18em)'} height="85vh">
<FullCalendar
ref={calendarRef}
locale="it"
locale={locale}
height="100%"
selectable={true}
slotMinTime="05:00:00"
Expand Down Expand Up @@ -595,7 601,7 @@ export default function CalendarView() {
})
}}
eventChange={(info) => {
eventEditSubmit(data)
eventEditSubmit(info)
}}
editable={true}
events={events}
Expand Down Expand Up @@ -648,8 654,8 @@ export default function CalendarView() {
setRecurrAction(e.target.value)
}}
>
<FormControlLabel value="0" control={<Radio />} label="This event" />
<FormControlLabel value="1" control={<Radio />} label="This and following events" />
<FormControlLabel value="0" control={<Radio />} label={translate("ess.calendar.event.recurring.thisev")} />
<FormControlLabel value="1" control={<Radio />} label={translate("ess.calendar.event.recurring.thisandfoll")} />
{
//disabled because it is tricky to handle
//<FormControlLabel value="2" control={<Radio />} label="All events" />
Expand Down Expand Up @@ -725,7 731,7 @@ export default function CalendarView() {
<Box sx={{ m: 0.5 }}>
<Grid container justifyContent="flex-end">
<IconButton onClick={() => {
setEditDialog({ //TODO: handle recurring ev
setEditDialog({
open: true,
record: popover.record
});
Expand Down
Loading

0 comments on commit 1548e24

Please sign in to comment.