Initial push of Plunk Next

This commit is contained in:
Dries Augustyns
2025-12-01 09:56:56 +01:00
parent 07cea20262
commit ff1876d580
566 changed files with 89036 additions and 28423 deletions
+67
View File
@@ -0,0 +1,67 @@
import useSWR from 'swr';
export interface Contact {
id: string;
email: string;
data?: Record<string, unknown>;
}
export interface ContactsResponse {
contacts: Contact[];
total: number;
}
interface UseContactsOptions {
limit?: number;
search?: string;
}
/**
* Hook to fetch contacts with optional search
*/
export function useContacts(options: UseContactsOptions = {}) {
const {limit = 50, search} = options;
const params = new URLSearchParams();
params.set('limit', limit.toString());
if (search) {
params.set('search', search);
}
const {data, error, mutate, isLoading} = useSWR<ContactsResponse>(
`/contacts?${params.toString()}`,
{
revalidateOnFocus: false,
dedupingInterval: 10000, // Prevent duplicate requests within 10 seconds
},
);
return {
contacts: data?.contacts || [],
total: data?.total || 0,
error,
isLoading,
mutate,
};
}
/**
* Hook to fetch available contact fields for variable usage
*/
export function useContactFields() {
const {data, error, mutate, isLoading} = useSWR<{fields: string[]}>(
'/contacts/fields',
{
revalidateOnFocus: false,
// Cache fields for longer since they don't change often
dedupingInterval: 60000, // 1 minute
},
);
return {
fields: data?.fields || [],
error,
isLoading,
mutate,
};
}