43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { create } from 'zustand';
|
|
|
|
export type ContactCategory = 'Adult' | 'Teenager' | 'Kid';
|
|
export type ContactStatus = 'Active' | 'Return Visit' | 'Bible Study' | 'Not Interested' | 'Do Not Call';
|
|
|
|
export interface Contact {
|
|
id: string;
|
|
ownerId: string;
|
|
fullName: string;
|
|
address?: string;
|
|
householdCount: number;
|
|
gender?: string;
|
|
category: ContactCategory;
|
|
status: ContactStatus;
|
|
tags: string[];
|
|
notes?: string;
|
|
territoryCode?: string;
|
|
latitude?: number;
|
|
longitude?: number;
|
|
createdAt: number;
|
|
updatedAt: number;
|
|
}
|
|
|
|
interface ContactStore {
|
|
contacts: Contact[];
|
|
setContacts: (contacts: Contact[]) => void;
|
|
addContact: (contact: Contact) => void;
|
|
updateContact: (id: string, updates: Partial<Contact>) => void;
|
|
removeContact: (id: string) => void;
|
|
}
|
|
|
|
export const useContactStore = create<ContactStore>((set) => ({
|
|
contacts: [],
|
|
setContacts: (contacts) => set({ contacts }),
|
|
addContact: (contact) => set((state) => ({ contacts: [...state.contacts, contact] })),
|
|
updateContact: (id, updates) =>
|
|
set((state) => ({
|
|
contacts: state.contacts.map((c) => (c.id === id ? { ...c, ...updates } : c)),
|
|
})),
|
|
removeContact: (id) =>
|
|
set((state) => ({ contacts: state.contacts.filter((c) => c.id !== id) })),
|
|
}));
|