Skip to content

Commit

Permalink
fix(reports): get correct value for publisher first report
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Dec 16, 2024
1 parent 795e202 commit db6f6a1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const useFirstReport = () => {

const minDateFormatted = formatDate(new Date(minDate), 'yyyy/MM/dd');

const firstReport = newPerson.person_data.first_report.value;
const firstReport = newPerson.person_data.first_report?.value;

const currentFirstReport = firstReport
? formatDate(new Date(firstReport), 'yyyy/MM/dd')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { monthNamesState } from '@states/app';
import { currentMonthServiceYear } from '@utils/date';
import { congFieldServiceReportsState } from '@states/field_service_reports';
import { branchFieldReportsState } from '@states/branch_field_service_reports';
import useCurrentUser from '@hooks/useCurrentUser';
import { formatDate } from '@services/dateformat';
import usePerson from '@features/persons/hooks/usePerson';

const useMonthItem = ({ month, person }: MonthItemProps) => {
const { first_report } = useCurrentUser();

const {
personIsEnrollmentActive,
personIsBaptizedPublisher,
Expand All @@ -25,6 +23,35 @@ const useMonthItem = ({ month, person }: MonthItemProps) => {
const [showEdit, setShowEdit] = useState(false);
const [editorOpen, setEditorOpen] = useState(false);

const first_report = useMemo(() => {
if (!person) return;

if (person.person_data.first_report?.value) {
return formatDate(
new Date(person.person_data.first_report.value),
'yyyy/MM'
);
}

// get all status history
let history = [
...person.person_data.publisher_unbaptized.history,
...person.person_data.publisher_baptized.history,
];

history = history.filter(
(record) => !record._deleted && record.start_date?.length > 0
);

history.sort((a, b) => a.start_date.localeCompare(b.start_date));

if (history.length === 0) return;

const firstDate = new Date(history.at(0).start_date);

return formatDate(firstDate, 'yyyy/MM');
}, [person]);

const branchReport = useMemo(() => {
return branchReports.find((record) => record.report_date === month);
}, [branchReports, month]);
Expand Down Expand Up @@ -63,6 +90,7 @@ const useMonthItem = ({ month, person }: MonthItemProps) => {
}, [month]);

const not_publisher = useMemo(() => {
console.log(month, first_report);
if (!first_report || first_report?.length === 0) return true;

if (month < first_report) return true;
Expand Down

0 comments on commit db6f6a1

Please sign in to comment.