Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export type AuxiliaryPioneersProps = {
wholeYear: boolean;
year: string;
month: string;
publisherGroup: string;
period: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,62 @@
import useReportMonthly from '@features/reports/hooks/useReportMonthly';

const useAuxiliaryPioneers = ({
month,
wholeYear,
year,
publisherGroup,
period,
}: AuxiliaryPioneersProps) => {
const { t } = useAppTranslation();

const { getAPYears, getAPMonths } = usePersons();
const { personHasReportYear, getAPReportsYear } = useReportYearly();
const { personHasReport, getAPReportsMonth } = useReportMonthly();

// Helper to filter persons by group
const filterByGroup = (persons: PersonType[]) => {
if (publisherGroup === 'all') return persons;
return persons.filter((p) =>
p.person_data.groups?.includes(publisherGroup)
);
};

// Determine period
const isWholeYear = period === 'serviceYear';
const selectedMonth = isWholeYear ? '' : period;

const field_reports = useMemo(() => {
let result: CongFieldServiceReportType[];

if (wholeYear) {
if (isWholeYear) {
result = getAPReportsYear(year);
} else {
result = getAPReportsMonth(selectedMonth);
}

if (!wholeYear) {
result = getAPReportsMonth(month);
}

return result;
}, [wholeYear, year, month, getAPReportsYear, getAPReportsMonth]);
if (publisherGroup === 'all') return result;
return result.filter((r) => r.person_data.groups?.includes(publisherGroup));
}, [
isWholeYear,
year,
selectedMonth,
getAPReportsYear,
getAPReportsMonth,
publisherGroup,
]);

const persons = useMemo(() => {
let persons: PersonType[];

if (wholeYear) {
if (isWholeYear) {
persons = getAPYears(year);
} else {
persons = getAPMonths(selectedMonth);
}

if (!wholeYear) {
persons = getAPMonths(month);
}

return persons;
}, [wholeYear, year, month, getAPYears, getAPMonths]);
return filterByGroup(persons);
}, [

Check warning on line 59 in src/features/reports/publisher_records/years_stats/auxiliary_pioneers/useAuxiliaryPioneers.tsx

View workflow job for this annotation

GitHub Actions / Test application

React Hook useMemo has a missing dependency: 'filterByGroup'. Either include it or remove the dependency array
isWholeYear,
year,
selectedMonth,
getAPYears,
getAPMonths,
publisherGroup,
]);

const total = useMemo(() => {
return persons.length;
Expand All @@ -57,12 +76,12 @@
for (const person of persons) {
let hasReport = false;

if (wholeYear) {
if (isWholeYear) {
hasReport = personHasReportYear(person, year);
}

if (!wholeYear) {
hasReport = personHasReport(person, month);
if (!isWholeYear) {
hasReport = personHasReport(person, selectedMonth);
}

if (hasReport) shared++;
Expand All @@ -71,7 +90,14 @@
}

return { shared, none };
}, [persons, year, wholeYear, month, personHasReportYear, personHasReport]);
}, [
persons,
isWholeYear,
year,
selectedMonth,
personHasReportYear,
personHasReport,
]);

const hours = useMemo(() => {
const sum = field_reports.reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export type FulltimeServantsProps = {
wholeYear: boolean;
year: string;
month: string;
publisherGroup: string;
period: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,62 @@
import useReportMonthly from '@features/reports/hooks/useReportMonthly';

const useFulltimeServants = ({
month,
wholeYear,
year,
publisherGroup,
period,
}: FulltimeServantsProps) => {
const { t } = useAppTranslation();

const { getFTSYears, getFTSMonths } = usePersons();
const { personHasReportYear, getFTSReportsYear } = useReportYearly();
const { personHasReport, getFTSReportsMonth } = useReportMonthly();

// Helper to filter persons by group
const filterByGroup = (persons: PersonType[]) => {
if (publisherGroup === 'all') return persons;
return persons.filter((p) =>
p.person_data.groups?.includes(publisherGroup)
);
};

// Determine period
const isWholeYear = period === 'serviceYear';
const selectedMonth = isWholeYear ? '' : period;

const field_reports = useMemo(() => {
let result: CongFieldServiceReportType[];

if (wholeYear) {
if (isWholeYear) {
result = getFTSReportsYear(year);
} else {
result = getFTSReportsMonth(selectedMonth);
}

if (!wholeYear) {
result = getFTSReportsMonth(month);
}

return result;
}, [wholeYear, year, month, getFTSReportsYear, getFTSReportsMonth]);
if (publisherGroup === 'all') return result;
return result.filter((r) => r.person_data.groups?.includes(publisherGroup));
}, [
isWholeYear,
year,
selectedMonth,
getFTSReportsYear,
getFTSReportsMonth,
publisherGroup,
]);

const persons = useMemo(() => {
let persons: PersonType[];

if (wholeYear) {
if (isWholeYear) {
persons = getFTSYears(year);
} else {
persons = getFTSMonths(selectedMonth);
}

if (!wholeYear) {
persons = getFTSMonths(month);
}

return persons;
}, [wholeYear, year, month, getFTSYears, getFTSMonths]);
return filterByGroup(persons);
}, [

Check warning on line 59 in src/features/reports/publisher_records/years_stats/fulltime_servants/useFulltimeServants.tsx

View workflow job for this annotation

GitHub Actions / Test application

React Hook useMemo has a missing dependency: 'filterByGroup'. Either include it or remove the dependency array
isWholeYear,
year,
selectedMonth,
getFTSYears,
getFTSMonths,
publisherGroup,
]);

const total = useMemo(() => {
return persons.length;
Expand All @@ -57,12 +76,12 @@
for (const person of persons) {
let hasReport = false;

if (wholeYear) {
if (isWholeYear) {
hasReport = personHasReportYear(person, year);
}

if (!wholeYear) {
hasReport = personHasReport(person, month);
if (!isWholeYear) {
hasReport = personHasReport(person, selectedMonth);
}

if (hasReport) shared++;
Expand All @@ -71,7 +90,14 @@
}

return { shared, none };
}, [persons, year, wholeYear, month, personHasReportYear, personHasReport]);
}, [
persons,
isWholeYear,
year,
selectedMonth,
personHasReportYear,
personHasReport,
]);

const hours = useMemo(() => {
const sum = field_reports.reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export type PublishersProps = {
wholeYear: boolean;
year: string;
month: string;
publisherGroup: string;
period: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,59 @@
import useReportYearly from '@features/reports/hooks/useReportYearly';
import useReportMonthly from '@features/reports/hooks/useReportMonthly';

const usePublishers = ({ month, wholeYear, year }: PublishersProps) => {
const usePublishers = ({ year, publisherGroup, period }: PublishersProps) => {
const { t } = useAppTranslation();

const { getPublisherYears, getPublisherMonths } = usePersons();
const { personHasReportYear, getPublisherReportsYear } = useReportYearly();
const { personHasReport, getPublisherReportsMonth } = useReportMonthly();

// Helper to filter persons by group
const filterByGroup = (persons: PersonType[]) => {
if (publisherGroup === 'all') return persons;
return persons.filter((p) =>
p.person_data.groups?.includes(publisherGroup)
);
};

// Determine period
const isWholeYear = period === 'serviceYear';
const selectedMonth = isWholeYear ? '' : period;

const field_reports = useMemo(() => {
let result: CongFieldServiceReportType[];

if (wholeYear) {
if (isWholeYear) {
result = getPublisherReportsYear(year);
} else {
result = getPublisherReportsMonth(selectedMonth);
}

if (!wholeYear) {
result = getPublisherReportsMonth(month);
}

return result;
if (publisherGroup === 'all') return result;
return result.filter((r) => r.person_data.groups?.includes(publisherGroup));
}, [
wholeYear,
isWholeYear,
year,
month,
selectedMonth,
getPublisherReportsYear,
getPublisherReportsMonth,
publisherGroup,
]);

const persons = useMemo(() => {
let persons: PersonType[];

if (wholeYear) {
if (isWholeYear) {
persons = getPublisherYears(year);
} else {
persons = getPublisherMonths(selectedMonth);
}

if (!wholeYear) {
persons = getPublisherMonths(month);
}

return persons;
}, [wholeYear, year, month, getPublisherYears, getPublisherMonths]);
return filterByGroup(persons);
}, [

Check warning on line 55 in src/features/reports/publisher_records/years_stats/publishers/usePublishers.tsx

View workflow job for this annotation

GitHub Actions / Test application

React Hook useMemo has a missing dependency: 'filterByGroup'. Either include it or remove the dependency array
isWholeYear,
year,
selectedMonth,
getPublisherYears,
getPublisherMonths,
publisherGroup,
]);

const total = useMemo(() => {
return persons.length;
Expand All @@ -59,12 +72,12 @@
for (const person of persons) {
let hasReport = false;

if (wholeYear) {
if (isWholeYear) {
hasReport = personHasReportYear(person, year);
}

if (!wholeYear) {
hasReport = personHasReport(person, month);
if (!isWholeYear) {
hasReport = personHasReport(person, selectedMonth);
}

if (hasReport) shared++;
Expand All @@ -73,7 +86,14 @@
}

return { shared, none };
}, [persons, year, wholeYear, month, personHasReportYear, personHasReport]);
}, [
persons,
isWholeYear,
year,
selectedMonth,
personHasReportYear,
personHasReport,
]);

const bible_studies = useMemo(() => {
const sum = field_reports.reduce(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type TotalStatisticsProps = {
year: string;
publisherGroup: string;
period: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import usePerson from '@features/persons/hooks/usePerson';
import useReportYearly from '@features/reports/hooks/useReportYearly';

const useTotalStatistics = ({ year }: TotalStatisticsProps) => {
const useTotalStatistics = ({ year, publisherGroup }: TotalStatisticsProps) => {
const { t } = useAppTranslation();

const { getPublisherAllYears, getPublishersActive, getAPMonths } =
Expand All @@ -30,11 +30,18 @@
return buildServiceYearsList();
}, []);

// Helper to filter persons by group
const filterByGroup = (persons) => {
if (publisherGroup === 'all') return persons;
return persons.filter((p) =>
p.person_data.groups?.includes(publisherGroup)
);
};

const publishers_list = useMemo(() => {
const result = getPublisherAllYears(year);

return result;
}, [year, getPublisherAllYears]);
return filterByGroup(result);
}, [year, getPublisherAllYears, publisherGroup]);

Check warning on line 44 in src/features/reports/publisher_records/years_stats/total_statistics/useTotalStatistics.tsx

View workflow job for this annotation

GitHub Actions / Test application

React Hook useMemo has a missing dependency: 'filterByGroup'. Either include it or remove the dependency array

const publishers_total = useMemo(() => {
const count = publishers_list.length;
Expand Down
Loading