Skip to content

Commit

Permalink
fix(schedules): display weekend public talk by circuit overseer
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Sep 27, 2023
1 parent 17ea0bb commit 4ae467e
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 40 deletions.
22 changes: 13 additions & 9 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PrivateLMMORoute from './components/PrivateLMMORoute';
import PrivatePublisherRoute from './components/PrivatePublisherRoute';
import PrivateVipRoute from './components/PrivateVipRoute';
import PrivatePublicTalkCoordinatorRoute from './components/PrivatePublicTalkCoordinatorRoute';
import PrivateWeekendMeetingRoute from './components/PrivateWeekendMeetingRoute';
import ErrorBoundary from './components/ErrorBoundary';
import { apiHostState, isLightThemeState, isOnlineState, visitorIDState } from './states/main';
import { congAccountConnectedState, congRoleState } from './states/congregation';
Expand Down Expand Up @@ -198,26 +199,29 @@ const App = ({ updatePwa }) => {
],
},
{
element: (
<PrivatePublicTalkCoordinatorRoute
isPublicTalkCoordinator={publicTalkCoordinatorRole || coordinatorRole}
/>
),
element: <PrivatePublicTalkCoordinatorRoute isPublicTalkCoordinator={publicTalkCoordinatorRole} />,
children: [
{
path: '/public-talks',
element: <PublicTalksList />,
},
{
path: '/weekend-schedules',
element: <WeekendMeetingSchedule />,
},
{
path: '/visiting-speakers',
element: <VisitingSpeakers />,
},
],
},
{
element: (
<PrivateWeekendMeetingRoute isWeekendMeetingRole={publicTalkCoordinatorRole || coordinatorRole} />
),
children: [
{
path: '/weekend-schedules',
element: <WeekendMeetingSchedule />,
},
],
},
],
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/classes/UserS4Records.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from 'date-fns';
import dateFormat from 'dateformat';
import appDb from '../indexedDb/mainDb';
import { UserS4DailyReportClass } from './UserS4DailyReport';

Expand Down Expand Up @@ -50,7 +50,7 @@ UserS4RecordsClass.prototype.get = async function (month_date) {
const monthStart = new Date(tmpMonthValue.getFullYear(), tmpMonthValue.getMonth(), 1);

const dailyRecord = new UserS4DailyReportClass();
dailyRecord.month = format(monthStart, 'yyyy/MM/dd');
dailyRecord.month = dateFormat(monthStart, 'yyyy/mm/dd');
dailyRecord.month_date = month_date;
await dailyRecord.save();

Expand Down
7 changes: 7 additions & 0 deletions src/components/PrivateWeekendMeetingRoute.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Navigate, Outlet } from 'react-router-dom';

function PrivateWeekendMeetingRoute({ isWeekendMeetingRole }) {
return isWeekendMeetingRole ? <Outlet /> : <Navigate to="/" />;
}

export default PrivateWeekendMeetingRoute;
46 changes: 34 additions & 12 deletions src/features/schedules/WeekendAssignments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const WeekendAssignments = () => {
const { weekToFormat } = useParams();
const week = weekToFormat.replaceAll('-', '/');

const [weekType, setWeekType] = useState(1);
const [chairman, setChairman] = useState('');
const [prayer, setPrayer] = useState('');
const [publicTalk, setPublicTalk] = useState('');
const [speaker1, setSpeaker1] = useState('');
const [speaker2, setSpeaker2] = useState('');
const [wsReader, setWsReader] = useState('');
const [wsArticle, setWsArticle] = useState('');
const [coTalkTitle, setCoTalkTitle] = useState('');

const { opening_prayer_WM_autoAssign } = Setting;

Expand All @@ -47,9 +49,11 @@ const WeekendAssignments = () => {

setChairman('');

setWeekType(scheduleData.week_type);
setChairman(pocketRole ? scheduleData.chairman_WM_dispName : scheduleData.chairman_WM);
setPrayer(pocketRole ? scheduleData.opening_prayerWM_dispName : scheduleData.opening_prayerWM);
setPublicTalk(scheduleData.public_talk_title);
setCoTalkTitle(sourceData.w_co_talk_title);
setSpeaker1(pocketRole ? scheduleData.speaker_1_dispName : scheduleData.speaker_1);
setSpeaker2(pocketRole ? scheduleData.speaker_2_dispName : scheduleData.speaker_2);
setWsArticle(sourceData.w_study_title);
Expand Down Expand Up @@ -93,18 +97,36 @@ const WeekendAssignments = () => {

<Box sx={{ margin: '20px 0' }}>
{/* Public Talk */}
<ScheduleRowAssignment
edit={false}
talk={true}
personA={speaker1}
personB={speaker2}
publicTalk={publicTalk}
studentAID={30}
studentBID={31}
assType={121}
assType2={120}
currentWeek={week}
/>
{weekType !== 2 && (
<ScheduleRowAssignment
edit={false}
talk={true}
personA={speaker1}
personB={speaker2}
publicTalk={publicTalk}
studentAID={30}
studentBID={31}
assType={121}
assType2={120}
currentWeek={week}
/>
)}

{/* CO Talk */}
{weekType === 2 && (
<ScheduleRowAssignment
co={true}
edit={false}
talk={true}
personA={Setting.co_displayName}
publicTalk={coTalkTitle}
studentAID={30}
studentBID={31}
assType={121}
assType2={120}
currentWeek={week}
/>
)}
</Box>

{/* Watchtower Study */}
Expand Down
4 changes: 2 additions & 2 deletions src/features/userFieldServiceReports/S4BibleStudiesField.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
import { format } from 'date-fns';
import dateFormat from 'dateformat';
import { useSetRecoilState } from 'recoil';
import { useTranslation } from 'react-i18next';
import Autocomplete from '@mui/material/Autocomplete';
Expand All @@ -26,7 +26,7 @@ const S4BibleStudiesField = ({ month, currentDate, value, setValue }) => {
return record.person_uid;
});

const tmpDate = format(new Date(currentDate), 'yyyy/MM/dd');
const tmpDate = dateFormat(new Date(currentDate), 'yyyy/mm/dd');

const currentReport = await UserS4Records.get(tmpDate);
currentReport.bibleStudies = values;
Expand Down
4 changes: 2 additions & 2 deletions src/features/userFieldServiceReports/S4DailyRecord.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { useTranslation } from 'react-i18next';
import { format } from 'date-fns';
import dateFormat from 'dateformat';
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';
Expand Down Expand Up @@ -29,7 +29,7 @@ const S4DailyRecord = ({ isOpen, month, date, setDate }) => {

useEffect(() => {
const handleInitializeReportDate = async () => {
const tmpDate = format(date, 'yyyy/MM/dd');
const tmpDate = dateFormat(date, 'yyyy/mm/dd');

const data = await UserS4Records.get(tmpDate);
setPlacements(data.placements);
Expand Down
4 changes: 2 additions & 2 deletions src/features/userFieldServiceReports/S4GenericField.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSetRecoilState } from 'recoil';
import { format } from 'date-fns';
import dateFormat from 'dateformat';
import { useTranslation } from 'react-i18next';
import AddCircleIcon from '@mui/icons-material/AddCircle';
import Box from '@mui/material/Box';
Expand All @@ -25,7 +25,7 @@ const S4GenericField = ({ fldType, month, currentDate, value = 0, setValue }) =>

const handleRecordUpdate = async (value) => {
const classField = getClassField();
const tmpDate = format(new Date(currentDate), 'yyyy/MM/dd');
const tmpDate = dateFormat(new Date(currentDate), 'yyyy/mm/dd');

const currentReport = await UserS4Records.get(tmpDate);
currentReport[classField] = value;
Expand Down
10 changes: 5 additions & 5 deletions src/features/userFieldServiceReports/S4HourField.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef, useState } from 'react';
import { format } from 'date-fns';
import dateFormat from 'dateformat';
import { useSetRecoilState } from 'recoil';
import { useTranslation } from 'react-i18next';
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
Expand Down Expand Up @@ -37,7 +37,7 @@ const S4HourField = ({ month, currentDate, value, setValue, timeStart, setTimeSt
newTimer = new Date(newTimer);
}

const tmpDate = format(new Date(currentDate), 'yyyy/MM/dd');
const tmpDate = dateFormat(new Date(currentDate), 'yyyy/mm/dd');
const durationStart = newTimer;
const currentReport = await UserS4Records.get(tmpDate);
currentReport.duration_start = durationStart;
Expand All @@ -49,7 +49,7 @@ const S4HourField = ({ month, currentDate, value, setValue, timeStart, setTimeSt
const handlePauseTimer = async () => {
clearInterval(runClock.current);

const tmpDate = format(new Date(currentDate), 'yyyy/MM/dd');
const tmpDate = dateFormat(new Date(currentDate), 'yyyy/mm/dd');

const currentReport = await UserS4Records.get(tmpDate);
currentReport.duration = value;
Expand All @@ -70,9 +70,9 @@ const S4HourField = ({ month, currentDate, value, setValue, timeStart, setTimeSt
const isValid = value === null || !isNaN(timestamp);

if (isValid) {
const durationValue = format(new Date(value), 'HH:mm:ss');
const durationValue = dateFormat(new Date(value), 'HH:MM:ss');

const tmpDate = format(new Date(currentDate), 'yyyy/MM/dd');
const tmpDate = dateFormat(new Date(currentDate), 'yyyy/mm/dd');

const currentReport = await UserS4Records.get(tmpDate);
currentReport.duration = durationValue;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/DashboardMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const DashboardMenu = () => {
{
title: t('publicTalksList'),
icon: <ListAltIcon />,
visible: publicTalkCoordinatorRole || coordinatorRole,
visible: publicTalkCoordinatorRole,
navigateTo: '/public-talks',
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/pages/WeeklyAssignments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ const WeeklyAssignments = () => {
};

const handlePreviousWeek = () => {
const weekDate = dateFormat(previousWeek, 'mm-dd-yyyy');
const weekDate = dateFormat(previousWeek, 'yyyy-mm-dd');
navigate(`/schedules/view/${weekDate}`);
};

const handleNextWeek = () => {
const weekDate = dateFormat(nextWeek, 'mm-dd-yyyy');
const weekDate = dateFormat(nextWeek, 'yyyy-mm-dd');
navigate(`/schedules/view/${weekDate}`);
};

Expand Down
6 changes: 3 additions & 3 deletions src/utils/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getI18n } from 'react-i18next';
import { format } from 'date-fns';
import dateFormat from 'dateformat';
import { promiseSetRecoil } from 'recoil-outside';
import { initAppDb } from '../indexedDb/dbUtility';
import { dbGetNotifications } from '../indexedDb/dbNotifications';
Expand Down Expand Up @@ -229,12 +229,12 @@ export const getCurrentExistingWeekDate = async () => {
const diff = today.getDate() - day + (day === 0 ? -6 : 1);
let monDay = new Date(today.setDate(diff));

let currentWeek = format(monDay, 'yyyy/mm/dd');
let currentWeek = dateFormat(monDay, 'yyyy/mm/dd');
let isExist = false;

if (schedules.length > 0) {
do {
const fDate = format(monDay, 'yyyy/mm/dd');
const fDate = dateFormat(monDay, 'yyyy/mm/dd');
const schedule = schedules.find((data) => data.weekOf === fDate);
if (schedule) {
currentWeek = fDate;
Expand Down

0 comments on commit 4ae467e

Please sign in to comment.