diff --git a/functions/src/demands.ts b/functions/src/demands.ts index 62878f7..de6a56c 100644 --- a/functions/src/demands.ts +++ b/functions/src/demands.ts @@ -12,17 +12,19 @@ import { HttpsError } from "firebase-functions/v2/https"; import { logger } from "firebase-functions/v2"; import { holidays } from "./holidays"; -function mealAirtable2FamilyDemand(demand: AirTableRecord, cityName: string, active: boolean): FamilyDemand { +function mealAirtable2FamilyDemand(demand: AirTableRecord, familyCityName: string, volunteerCityName: string, active: boolean): FamilyDemand { return { id: demand.id, date: demand.fields["DATE"], - city: cityName, // id and needs to be name + familyCityName, + city: familyCityName, familyLastName: demand.fields.Name, district: getSafeFirstArrayElement(demand.fields["מחוז"], ""), status: Status.Occupied, mainBaseFamilyId: getSafeFirstArrayElement(demand.fields["משפחה"], ""), districtBaseFamilyId: "N/A", volunteerId: getSafeFirstArrayElement(demand.fields["מתנדב"], undefined), + volunteerCityName, isFamilyActive: active, transpotingVolunteerId: getSafeFirstArrayElement(demand.fields["מתנדב משנע"], undefined), }; @@ -44,7 +46,10 @@ export async function getDemands2( const mealsQuery = new AirTableQuery("ארוחות", (m) => { const family = families.find(f => f.id == getSafeFirstArrayElement(m.fields["משפחה"], "")); - return mealAirtable2FamilyDemand(m, getCityName(getSafeFirstArrayElement(m.fields["עיר"], "")), family ? family.active : false); + return mealAirtable2FamilyDemand(m, + getCityName(getSafeFirstArrayElement(m.fields["עיר"], "")), + getCityName(getSafeFirstArrayElement(m.fields["עיר מתנדב"], "")), + family ? family.active : false); }); const filters: string[] = []; @@ -101,13 +106,14 @@ export async function getDemands2( addedOpenDemands.push({ id: getCalcDemandID(family.id, actualDate, family.cityId), date: actualDate, - city: getCityName(family.cityId), + familyCityName: getCityName(family.cityId), district: family.district, status: Status.Available, familyLastName: family.name, mainBaseFamilyId: family.id, districtBaseFamilyId: "N/A", volunteerId: "", + volunteerCityName: "", isFamilyActive: family.active, }); } @@ -125,13 +131,14 @@ export async function getDemands2( addedOpenDemands.push({ id: family.id + holidayDate, date: holidayDate, - city: getCityName(family.cityId), + familyCityName: getCityName(family.cityId), district: family.district, status: Status.Available, familyLastName: family.name, mainBaseFamilyId: family.id, districtBaseFamilyId: "N/A", volunteerId: "", + volunteerCityName: "", isFamilyActive: family.active, }); } @@ -183,13 +190,15 @@ export async function updateFamilityDemand(demandId: string, demandDistrict: str const possibleDemands = await getDemands2(demandDistrict, Status.Occupied, date, date); demand = possibleDemands.find(d => d.mainBaseFamilyId == familyId && d.date == date); } else { - const cities = await getCities(); + const _cities = await getCities(); + const getCityName = (id: string) => _cities.find(c => c.id == id)?.name || ""; // eslint-disable-next-line new-cap - demand = await AirTableGet("ארוחות", demandId, (rec) => { - const city = cities.find(c => c.id == getSafeFirstArrayElement(rec.fields["עיר"], "")); - return mealAirtable2FamilyDemand(rec, city?.name || "N/A", true); - }); + demand = await AirTableGet("ארוחות", demandId, (m) => mealAirtable2FamilyDemand(m, + getCityName(getSafeFirstArrayElement(m.fields["עיר"], "")), + getCityName(getSafeFirstArrayElement(m.fields["עיר מתנדב"], "")), + true) + ); } if ((!demand && !isRegistering) || demand && isRegistering) { @@ -250,7 +259,7 @@ export async function updateFamilityDemand(demandId: string, demandDistrict: str await addNotificationToQueue("שיבוץ בוטל!", `תאריך: ${demand.date} משפחה: ${demand.familyLastName} בוטל ע״י: ${performingUser} -עיר: ${demand.city} +עיר: ${demand.familyCityName} `, NotificationChannels.Registrations, [], adminsIds); } } else { diff --git a/functions/src/scheduled-functions.ts b/functions/src/scheduled-functions.ts index 40898f5..4237025 100644 --- a/functions/src/scheduled-functions.ts +++ b/functions/src/scheduled-functions.ts @@ -174,7 +174,7 @@ export async function SendLinkOrInstall() { const query = new AirTableQuery<{ id: string, familyCount: number }>("מחוז", (rec) => ({ id: rec.id, familyCount: rec.fields["כמות משפחות פעילות במחוז"], - })) + })); const districtsIdsWithFamilies = (await query.execute()).filter(d => d.familyCount > 0).map(d => d.id); const users = await db.collection(Collections.Users).where("active", "==", true).get(); diff --git a/src/charts.tsx b/src/charts.tsx index b7082d7..ef91634 100644 --- a/src/charts.tsx +++ b/src/charts.tsx @@ -2,8 +2,8 @@ import React, { useEffect, useRef, useState } from 'react'; import { Chart } from 'primereact/chart'; import { MultiSelect } from 'primereact/multiselect'; import dayjs from 'dayjs'; -import {AppServices, FamilyCompact, FamilyDemand, UserInfo, VolunteerInfo} from './types'; -import {getDemands, getVolunteerInfo, handleSearchUsers, updateDemandTransportation, updateFamilityDemand} from './api'; +import { AppServices, FamilyCompact, FamilyDemand, UserInfo, VolunteerInfo } from './types'; +import { getDemands, getVolunteerInfo, handleSearchUsers, updateDemandTransportation, updateFamilityDemand } from './api'; import { InProgress, PhoneNumber, WeekSelectorSlider } from './common-ui'; import { SelectButton } from 'primereact/selectbutton'; @@ -17,7 +17,7 @@ import { ProgressSpinner } from 'primereact/progressspinner'; import { ProgressBar } from 'primereact/progressbar'; import { confirmPopup } from 'primereact/confirmpopup'; import { Recipient } from './types'; -import {Dialog} from "primereact/dialog"; +import { Dialog } from "primereact/dialog"; interface DemandChartProps { data: FamilyDemand[]; @@ -27,7 +27,7 @@ interface DemandChartProps { showFilterByVolunteer?: boolean; onCancellationPerformed?: () => void; onSelectFamily?: (family: GroupedFamily | undefined) => void, - setLoading:(isLoading:boolean)=>void; + setLoading: (isLoading: boolean) => void; setReload: (reload: number | ((prev: number) => number)) => void; } @@ -76,7 +76,7 @@ const filterOnlyFulfilled = (f: FamilyDemand) => f.status === "תפוס"; export function Stats({ userInfo, appServices }: StatsProps) { const [loading, setLoading] = useState(false); const [data, setData] = useState([]); - const [selectedWeeks, setSelectedWeeks] = useState<[number,number]>([0, 4]); + const [selectedWeeks, setSelectedWeeks] = useState<[number, number]>([0, 4]); const [selectedDistricts, setSelectedDistricts] = useState([]); //const calendar = useRef(null); const [mode, setMode] = useState(Modes.Open); @@ -120,7 +120,7 @@ export function Stats({ userInfo, appServices }: StatsProps) { מי יכול.ה לסייע בבישול בחודש הקרוב 🙏 `; - for (const city of sortedCities){ + for (const city of sortedCities) { // Sort families alphabetically within each city const sortedFamilies = sortFamilies(groupedData[city]); @@ -209,7 +209,7 @@ export function Stats({ userInfo, appServices }: StatsProps) { {/* {error && {error}} */} {mode === Modes.Open || mode === Modes.Fulfilled ? - setSelectedFamily(family)} showFilterByVolunteer={showFilterByVolunteer} onCancellationPerformed={() => { @@ -217,13 +217,13 @@ export function Stats({ userInfo, appServices }: StatsProps) { setReload(prev => prev + 1) } } /> : - + } ); } -export const DemandList: React.FC = ({ data, isShowOpen, appServices, userInfo, showFilterByVolunteer, +export const DemandList: React.FC = ({ data, isShowOpen, appServices, userInfo, showFilterByVolunteer, onCancellationPerformed, onSelectFamily, setLoading, setReload }) => { let demands = data.filter(isShowOpen ? filterOnlyOpen : filterOnlyFulfilled); const [showFamilyDetails, setShowFamilyDetails] = useState(); @@ -238,7 +238,7 @@ export const DemandList: React.FC = ({ data, isShowOpen, appSe const [showRecipientModal, setShowRecipientModal] = useState(false); const [recipients, setRecipients] = useState([]); const [filteredUsers, setFilteredUsers] = useState([]); // Adjust the type as needed - const [transportingVolunteer, setTransportingVolunteer] = useState(undefined); + const [transportingVolunteer, setTransportingVolunteer] = useState(undefined); const openRecipientModal = () => { setShowRecipientModal(true); @@ -270,7 +270,7 @@ export const DemandList: React.FC = ({ data, isShowOpen, appSe appServices.showMessage("error", "שמירה נכשלה", error.message); console.error("Error updating transportation:", error); }) - .finally(()=>setLoading(false)); + .finally(() => setLoading(false)); } closeRecipientModal(); // Close the modal after success } catch (error) { @@ -283,17 +283,16 @@ export const DemandList: React.FC = ({ data, isShowOpen, appSe selectedDateInfo: DateInfo | undefined, volunteerInfo: VolunteerInfo | undefined ) => { - const message = ` - דרוש שינוע🚙 + const message = `דרוש שינוע🚙 - מי יכול.ה לעזור בשינוע? +מי יכול.ה לעזור בשינוע? - בתאריך ${selectedDateInfo ? selectedDateInfo.date : ""} +בתאריך ${selectedDateInfo ? selectedDateInfo.date : ""} - מ${volunteerInfo ? volunteerInfo.city : ""} - ל${selectedDateInfo && selectedDateInfo.parentFamily ? `${selectedDateInfo.parentFamily.city}` : ""} - למשפחת${selectedDateInfo && selectedDateInfo.parentFamily ? ` ${selectedDateInfo.parentFamily.familyLastName}` : ""} - `; +מ${volunteerInfo ? volunteerInfo.city : ""} +ל${selectedDateInfo && selectedDateInfo.parentFamily ? `${selectedDateInfo.parentFamily.city}` : ""} +למשפחת${selectedDateInfo && selectedDateInfo.parentFamily ? ` ${selectedDateInfo.parentFamily.familyLastName}` : ""}`; + // Handle the message, e.g., displaying it in a modal or copying to clipboard console.log(message); // Or whatever logic you need to use the message navigator.clipboard.writeText(message); @@ -337,7 +336,7 @@ export const DemandList: React.FC = ({ data, isShowOpen, appSe if (onSelectFamily) onSelectFamily(undefined); // todo push nav state - }} reloadOpenDemands={() => { }} detailsOnly={true} actualUserId={""}/>; + }} reloadOpenDemands={() => { }} detailsOnly={true} actualUserId={""} />; } const handleDateClick = (e: any, dateInfo: DateInfo) => { @@ -410,10 +409,10 @@ export const DemandList: React.FC = ({ data, isShowOpen, appSe {selectedDateInfo && (volunteerInfo ? <>
שם מבשל: {volunteerInfo.firstName + " " + volunteerInfo.lastName}
- + {transportingVolunteer && -
שם משנע: {transportingVolunteer ? transportingVolunteer.firstName + " " + transportingVolunteer.lastName : undefined}
} - {transportingVolunteer && } +
שם משנע: {transportingVolunteer ? transportingVolunteer.firstName + " " + transportingVolunteer.lastName : undefined}
} + {transportingVolunteer && }