Skip to content

Commit

Permalink
feat(settings): add new option to choose the exact meeting date on S-140
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Oct 5, 2023
1 parent 6bdd6c0 commit a7918fd
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 279 deletions.
15 changes: 14 additions & 1 deletion src/classes/Schedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ SchedulesClass.prototype.S140Data = function (scheduleName) {
const scheduleData = this.get(week);
const sourceData = Sources.get(week).local();

let midDay = +Setting.midweek_meeting_day;
const [varYear, varMonth, varDay] = week.split('/');
midDay = parseInt(varDay, 10) + midDay - 1;
const lDate = new Date(varYear, varMonth - 1, midDay);

const meetingDate = t('longDateFormat', {
lng: sourceLang,
ns: 'source',
month: Setting.monthNames()[lDate.getMonth()],
date: lDate.getDate(),
year: lDate.getFullYear(),
});

// pgm start
const time = {};
time.pgmStart = meetingStart;
Expand Down Expand Up @@ -407,7 +420,7 @@ SchedulesClass.prototype.S140Data = function (scheduleName) {
const obj = {};
obj.week = week;
obj.scheduleData = scheduleData;
obj.sourceData = { ...sourceData, ...time };
obj.sourceData = { ...sourceData, ...time, meeting_date: meetingDate };
data.push(obj);
}

Expand Down
2 changes: 2 additions & 0 deletions src/classes/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SettingClass {
this.opening_prayer_WM_autoAssign = false;
this.user_members_delegate = [];
this.weekend_meeting_day = 6;
this.midweek_meeting_useExactDate = false;
}
}

Expand Down Expand Up @@ -61,6 +62,7 @@ SettingClass.prototype.load = async function () {
this.user_members_delegate = congData.user_members_delegate || [];
this.opening_prayer_WM_autoAssign = congData.opening_prayer_WM_autoAssign;
this.weekend_meeting_day = congData.weekend_meeting_day;
this.midweek_meeting_useExactDate = congData.midweek_meeting_useExactDate;
};

SettingClass.prototype.update = async function (setting, overwrite) {
Expand Down
26 changes: 23 additions & 3 deletions src/features/settings/BasicSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
openingPrayerMMAutoAssignState,
openingPrayerWMAutoAssignState,
weekendMeetingDayState,
midweekMeetingExactDateState,
} from '../../states/congregation';
import { scheduleUseFullnameState } from '../../states/schedule';
import { generateDisplayName } from '../../utils/person';
Expand All @@ -35,6 +36,7 @@ const BasicSettings = () => {
const [autoAssignWMOpeningPrayer, setAutoAssignWMOpeningPrayer] = useRecoilState(openingPrayerWMAutoAssignState);
const [scheduleUseFullname, setScheduleUseFullname] = useRecoilState(scheduleUseFullnameState);
const [weekendMeetingDay, setWeekendMeetingDay] = useRecoilState(weekendMeetingDayState);
const [midweekMeetingExactDate, setMidweekMeetingExactDate] = useRecoilState(midweekMeetingExactDateState);

const congName = useRecoilValue(congNameState);
const congNumber = useRecoilValue(congNumberState);
Expand All @@ -48,6 +50,7 @@ const BasicSettings = () => {
const [tmpautoAssignWMOpeningPrayer, setTmpautoAssignWMOpeningPrayer] = useState(autoAssignWMOpeningPrayer);
const [useFullname, setUseFullname] = useState(scheduleUseFullname);
const [tempWeekendMeetingDay, setTempWeekendMeetingDay] = useState(weekendMeetingDay);
const [tmpMidweekMeetingExactDate, setTmpMidweekMeetingExactDate] = useState(midweekMeetingExactDate);

const roleLMMO = Setting.cong_role.includes('lmmo') || Setting.cong_role.includes('lmmo-backup');
const coordinatorRole = Setting.cong_role.includes('coordinator');
Expand Down Expand Up @@ -111,6 +114,12 @@ const BasicSettings = () => {
setWeekendMeetingDay(e.target.value);
};

const handleSwitchMMExactDate = async (value) => {
setTmpMidweekMeetingExactDate(value);
await Setting.update({ midweek_meeting_useExactDate: value });
setMidweekMeetingExactDate(value);
};

useEffect(() => {
setCoName(Setting.co_name || '');
setCoDisplayName(Setting.co_displayName || '');
Expand Down Expand Up @@ -217,6 +226,17 @@ const BasicSettings = () => {
</TextField>
</Box>

<FormControlLabel
control={
<Checkbox
checked={tmpautoAssignMMOpeningPrayer}
readOnly={!roleLMMO}
onChange={roleLMMO ? (e) => handleSwitchMMAutoAssignPrayer(e.target.checked) : null}
/>
}
label={t('autoAssignMMOpeningPrayer')}
/>

<FormControlLabel
control={
<Checkbox
Expand All @@ -231,12 +251,12 @@ const BasicSettings = () => {
<FormControlLabel
control={
<Checkbox
checked={tmpautoAssignMMOpeningPrayer}
checked={tmpMidweekMeetingExactDate}
readOnly={!roleLMMO}
onChange={roleLMMO ? (e) => handleSwitchMMAutoAssignPrayer(e.target.checked) : null}
onChange={roleLMMO ? (e) => handleSwitchMMExactDate(e.target.checked) : null}
/>
}
label={t('autoAssignMMOpeningPrayer')}
label={t('useExactMidweekMeetingDate')}
/>
</Box>

Expand Down
Loading

0 comments on commit a7918fd

Please sign in to comment.