feat: add stickiness round — daily Sadaqah tracker + Family Tree social loop
Two features scoped from the stickiness brainstorm, sharing one digest notification pipeline: Sadaqah tracker (new tab): a private daily giving journal, not a payment processor — the app logs, it never moves money. Streak tracking follows the proven pattern from dedicated apps (Sidq, Daily Sadaqa). Family visibility is strictly limited to streak counts via a SECURITY DEFINER RPC (nf_family_sadaqah_streaks) — amounts, causes, and notes never cross the member boundary, respecting the Islamic preference for giving privately. Entries can be dedicated 'in memory of' a deceased person from the Family Tree, with a memorial count (nf_memorial_sadaqah_count, count only) surfacing on that person's card. Family Tree social loop: a 'give sadaqah in memory of' link on every deceased person's card (cross-tab jump via a small requestedTab store in nav.js), plus completeness hints (missing birth date, missing photo, no relationships linked) feeding directly into the existing Coverage Dashboard recommendations engine rather than a new UI surface. Daily digest Edge Function + pg_cron (07:00 UTC): batches into one email per family member per day, sent only when there's real content — tree activity in the last 24h, a birthday/death-anniversary today, or a weekly sadaqah recap on Sundays. An empty day sends nothing, deliberately avoiding the notification-spam failure mode the research flagged. Protected by a shared secret header since it's cron-invoked, not user-triggered. Verified with a live manual invocation before relying on the schedule. Found and fixed two real bugs in nf_family_sadaqah_streaks during E2E testing: an ambiguous unqualified 'member_id' column reference colliding with the function's OUT parameter (42702), and a bigint/int type mismatch from count(*) (42804) — both would have 400'd on every call in production. Covered by e2e-sadaqah-tree.cjs (12/12). Full regression: 280/280 across all suites.
This commit is contained in:
@@ -382,6 +382,41 @@ export async function removeRelationship(id) {
|
||||
if (error) throw error;
|
||||
}
|
||||
|
||||
// ── Sadaqah — private daily journal. Family visibility is limited to
|
||||
// streak counts via nf_family_sadaqah_streaks (never amounts/causes/notes).
|
||||
export async function listSadaqahLog(familyId, memberId) {
|
||||
const { data, error } = await supabase.from('nf_sadaqah_log').select('*').eq('family_id', familyId).eq('member_id', memberId).order('log_date', { ascending: false });
|
||||
if (error) throw error;
|
||||
return (data || []).map(s => ({
|
||||
id: s.id, logDate: s.log_date, cause: s.cause, amount: s.amount,
|
||||
inMemoryOfPersonId: s.in_memory_of_person_id, notes: s.notes
|
||||
}));
|
||||
}
|
||||
export async function addSadaqahEntry(familyId, memberId, fields) {
|
||||
const { error } = await supabase.from('nf_sadaqah_log').insert({
|
||||
family_id: familyId, member_id: memberId, log_date: fields.logDate || new Date().toISOString().slice(0, 10),
|
||||
cause: fields.cause || null, amount: fields.amount ? Number(fields.amount) : null,
|
||||
in_memory_of_person_id: fields.inMemoryOfPersonId || null, notes: fields.notes || null
|
||||
});
|
||||
if (error) throw error;
|
||||
}
|
||||
export async function removeSadaqahEntry(id) {
|
||||
const { error } = await supabase.from('nf_sadaqah_log').delete().eq('id', id);
|
||||
if (error) throw error;
|
||||
}
|
||||
/** Family-visible streak counts only — no amounts, causes, or notes. */
|
||||
export async function getFamilySadaqahStreaks(familyId) {
|
||||
const { data, error } = await supabase.rpc('nf_family_sadaqah_streaks', { p_family_id: familyId });
|
||||
if (error) throw error;
|
||||
return (data || []).map(r => ({ memberId: r.member_id, currentStreak: r.current_streak, gaveToday: r.gave_today }));
|
||||
}
|
||||
/** Count of sadaqah given in memory of a person — count only, shown on their Tree card. */
|
||||
export async function getMemorialSadaqahCount(personId) {
|
||||
const { data, error } = await supabase.rpc('nf_memorial_sadaqah_count', { p_person_id: personId });
|
||||
if (error) throw error;
|
||||
return data || 0;
|
||||
}
|
||||
|
||||
// ── Insurance / Takaful — per-member: each family member logs their own
|
||||
// policies, but any family member (and the mutawalli dashboard) can read them. ──
|
||||
export async function listInsurancePolicies(familyId, memberId) {
|
||||
|
||||
Reference in New Issue
Block a user