diff --git a/src/features/greeting/Greeting.jsx b/src/features/greeting/Greeting.jsx index d6ab0c21..06f63bcc 100644 --- a/src/features/greeting/Greeting.jsx +++ b/src/features/greeting/Greeting.jsx @@ -5,7 +5,6 @@ import { nth, convertTimezone } from 'utils/date'; import EventBus from 'utils/eventbus'; import './greeting.scss'; -import events from './events.json'; const isEventsEnabled = localStorage.getItem('events') !== 'false'; export default class Greeting extends PureComponent { @@ -34,7 +33,10 @@ export default class Greeting extends PureComponent { const month = time.getMonth(); const date = time.getDate(); - const event = events.find((e) => e.month - 1 === month && e.date === date); + // Parse the customEvents from localStorage + const customEvents = JSON.parse(localStorage.getItem('customEvents') || '[]'); + + const event = customEvents.find((e) => e.month - 1 === month && e.date === date); if (event) { message = variables.getMessage(event.id); } diff --git a/src/features/greeting/options/GreetingOptions.jsx b/src/features/greeting/options/GreetingOptions.jsx index c2943a57..a462882e 100644 --- a/src/features/greeting/options/GreetingOptions.jsx +++ b/src/features/greeting/options/GreetingOptions.jsx @@ -77,6 +77,20 @@ const GreetingOptions = () => { setCustomEvents(defaultEvents); } + function updateEvent(index, updatedEvent) { + // Update the event in your state + setCustomEvents((prevEvents) => { + const newEvents = [...prevEvents]; + newEvents[index] = updatedEvent; + return newEvents; + }); + + // Update the event in localStorage + const customEvents = JSON.parse(localStorage.getItem('customEvents') || '[]'); + customEvents[index] = updatedEvent; + localStorage.setItem('customEvents', JSON.stringify(customEvents)); + } + const AdditionalOptions = () => { return ( @@ -158,7 +172,10 @@ const GreetingOptions = () => { this.message(e, true, index)} + onChange={(e) => { + const updatedEvent = { ...event, name: e.target.value }; + updateEvent(index, updatedEvent); + }} varient="outlined" style={{ padding: '0' }} /> @@ -168,11 +185,27 @@ const GreetingOptions = () => {
- + { + const updatedEvent = { ...event, month: parseInt(e.target.value, 10) }; + updateEvent(index, updatedEvent); + }} + />
- + { + const updatedEvent = { ...event, date: parseInt(e.target.value, 10) }; + updateEvent(index, updatedEvent); + }} + />