refactor: generate and use Supabase TypeScript types
Co-authored-by: Moheeb Zara <[email protected]>
This commit is contained in:
+4
-1
@@ -3,6 +3,8 @@
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import type { SupabaseClient } from '@supabase/supabase-js'
|
||||
import type { Database } from '@/types/database'
|
||||
|
||||
// ─── Auth ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -26,7 +28,7 @@ export async function getUser() {
|
||||
}
|
||||
|
||||
// ─── Helper: get current member (any non-inactive status) ────────────────────
|
||||
async function getMember(supabase: any, userId: string) {
|
||||
async function getMember(supabase: SupabaseClient<Database>, userId: string) {
|
||||
const { data } = await supabase
|
||||
.from('space_members')
|
||||
.select('space_id, role, display_name')
|
||||
@@ -670,6 +672,7 @@ export async function createSecret(formData: {
|
||||
const { data, error } = await supabase.from('secrets').insert({
|
||||
space_id: member.space_id,
|
||||
title: formData.title,
|
||||
label: formData.title,
|
||||
value: formData.value,
|
||||
description: formData.description,
|
||||
area: formData.area,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
import type { Database } from '@/types/database'
|
||||
|
||||
/**
|
||||
* Admin client using the service role key.
|
||||
@@ -6,7 +7,7 @@ import { createClient } from '@supabase/supabase-js'
|
||||
* NEVER expose this client to the browser.
|
||||
*/
|
||||
export function createAdminClient() {
|
||||
return createClient(
|
||||
return createClient<Database>(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.SUPABASE_SERVICE_ROLE_KEY!,
|
||||
{
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { createBrowserClient } from '@supabase/ssr'
|
||||
import type { Database } from '@/types/database'
|
||||
|
||||
export function createClient() {
|
||||
return createBrowserClient(
|
||||
return createBrowserClient<Database>(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createServerClient } from '@supabase/ssr'
|
||||
import { cookies } from 'next/headers'
|
||||
import type { Database } from '@/types/database'
|
||||
|
||||
/**
|
||||
* Especially important if using Fluid compute: Don't put this client in a
|
||||
@@ -9,7 +10,7 @@ import { cookies } from 'next/headers'
|
||||
export async function createClient() {
|
||||
const cookieStore = await cookies()
|
||||
|
||||
return createServerClient(
|
||||
return createServerClient<Database>(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
{
|
||||
|
||||
+35
-203
@@ -1,206 +1,38 @@
|
||||
// Enum values match live DB exactly
|
||||
export type MemberTier = 'plus' | 'basic' | 'associate'
|
||||
export type MemberRole = 'admin' | 'board' | 'treasurer' | 'member' | 'associate'
|
||||
export type MemberStatus = 'current' | 'late' | 'inactive' | 'unverified'
|
||||
export type TaskType = 'chore' | 'task'
|
||||
export type TaskStatus = 'open' | 'claimed' | 'in_progress' | 'overdue' | 'due_today' | 'completed' | 'done' | 'blocked'
|
||||
export type TaskRecurrence = 'none' | 'daily' | 'weekly' | 'biweekly' | 'monthly'
|
||||
export type ProjectStatus = 'backlog' | 'in_progress' | 'review' | 'done' | 'blocked'
|
||||
export type KBVisibility = 'all_members' | 'board' | 'admin_only'
|
||||
export type ContactType = 'vendor' | 'supplier' | 'partner' | 'landlord' | 'city'
|
||||
export type PaymentPlatform = 'paypal' | 'zeffy' | 'venmo' | 'cash'
|
||||
export type PaymentLinkStatus = 'linked' | 'unlinked'
|
||||
export type ChannelType = 'general' | 'area' | 'ops' | 'project'
|
||||
export type AreaLeadStatus = 'active' | 'vacant' | 'handoff'
|
||||
/**
|
||||
* Re-export types from the generated database types.
|
||||
* These types are auto-generated from the Supabase schema.
|
||||
*
|
||||
* To regenerate: Use the supabase_generate_typescript_types tool
|
||||
*/
|
||||
|
||||
export interface Space {
|
||||
id: string
|
||||
name: string
|
||||
slug: string
|
||||
city?: string
|
||||
invite_code: string
|
||||
require_approval: boolean
|
||||
public_member_directory: boolean
|
||||
webhook_secret?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
import type { Tables, Enums } from '@/types/database'
|
||||
|
||||
export interface SpaceMember {
|
||||
id: string
|
||||
space_id: string
|
||||
user_id: string
|
||||
display_name: string
|
||||
handle?: string
|
||||
email?: string
|
||||
phone?: string
|
||||
tier: MemberTier
|
||||
role: MemberRole
|
||||
status: MemberStatus
|
||||
joined_at: string
|
||||
approved: boolean
|
||||
has_card_access: boolean
|
||||
last_payment_at?: string
|
||||
last_paid_at?: string
|
||||
payment_status?: string
|
||||
payment_note?: string
|
||||
}
|
||||
// ─── Table Row Types ───────────────────────────────────────────────────────────
|
||||
export type Space = Tables<'spaces'>
|
||||
export type SpaceMember = Tables<'space_members'>
|
||||
export type Task = Tables<'tasks'>
|
||||
export type Project = Tables<'projects'>
|
||||
export type KnowledgeBase = Tables<'knowledge_base'>
|
||||
export type Secret = Tables<'secrets'>
|
||||
export type AreaLead = Tables<'area_leads'>
|
||||
export type Contact = Tables<'contacts'>
|
||||
export type Payment = Tables<'payments'>
|
||||
export type CommsChannel = Tables<'comms_channels'>
|
||||
export type CommsMessage = Tables<'comms_messages'>
|
||||
export type Integration = Tables<'integrations'>
|
||||
export type ActivityLog = Tables<'activity_log'>
|
||||
|
||||
export interface Task {
|
||||
id: string
|
||||
space_id: string
|
||||
task_type: TaskType
|
||||
title: string
|
||||
description?: string
|
||||
status: TaskStatus
|
||||
area?: string
|
||||
assigned_to?: string
|
||||
assigned_to_name?: string
|
||||
claimed_by?: string
|
||||
claimed_by_name?: string
|
||||
requested_by?: string
|
||||
requested_by_name?: string
|
||||
due_date?: string
|
||||
recurrence: TaskRecurrence
|
||||
last_done_at?: string
|
||||
subtask_completed?: number
|
||||
subtask_total?: number
|
||||
completed_at?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface Project {
|
||||
id: string
|
||||
space_id: string
|
||||
title: string
|
||||
description?: string
|
||||
status: ProjectStatus
|
||||
area?: string
|
||||
tags?: string[]
|
||||
assignee_names?: string[]
|
||||
task_count?: number
|
||||
tasks_completed?: number
|
||||
due_date?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface KnowledgeBase {
|
||||
id: string
|
||||
space_id: string
|
||||
title: string
|
||||
content?: string
|
||||
description?: string
|
||||
area?: string
|
||||
tags?: string[]
|
||||
visibility: KBVisibility
|
||||
access_level?: string
|
||||
is_pinned: boolean
|
||||
pinned?: boolean
|
||||
icon?: string
|
||||
updated_by_id?: string
|
||||
updated_by_name?: string
|
||||
updated_by?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface Secret {
|
||||
id: string
|
||||
space_id: string
|
||||
title: string
|
||||
description?: string
|
||||
value: string
|
||||
area?: string
|
||||
icon?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface AreaLead {
|
||||
id: string
|
||||
space_id: string
|
||||
area_code: string
|
||||
area_name: string
|
||||
lead_id?: string
|
||||
lead_handle?: string
|
||||
status: AreaLeadStatus
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface Contact {
|
||||
id: string
|
||||
space_id: string
|
||||
contact_type: ContactType
|
||||
code: string
|
||||
name: string
|
||||
email?: string
|
||||
phone?: string
|
||||
details?: string
|
||||
tags?: string[]
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface Payment {
|
||||
id: string
|
||||
space_id: string
|
||||
platform: PaymentPlatform
|
||||
amount: number
|
||||
from_identifier: string
|
||||
from_note?: string
|
||||
member_id?: string
|
||||
member_name?: string
|
||||
link_status: PaymentLinkStatus
|
||||
transaction_date: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface CommsChannel {
|
||||
id: string
|
||||
space_id: string
|
||||
name: string
|
||||
channel_type: ChannelType
|
||||
icon?: string
|
||||
area_reference?: string
|
||||
project_id?: string
|
||||
member_count?: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface CommsMessage {
|
||||
id: string
|
||||
space_id: string
|
||||
channel_id: string
|
||||
user_id: string
|
||||
display_name: string
|
||||
handle?: string
|
||||
content: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface Integration {
|
||||
id: string
|
||||
space_id: string
|
||||
platform: string
|
||||
name: string
|
||||
description?: string
|
||||
is_connected: boolean
|
||||
config?: any
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface ActivityLog {
|
||||
id: string
|
||||
space_id: string
|
||||
user_id: string
|
||||
display_name: string
|
||||
action: string
|
||||
entity_type: string
|
||||
entity_id: string
|
||||
details?: string
|
||||
created_at: string
|
||||
}
|
||||
// ─── Enum Types ────────────────────────────────────────────────────────────────
|
||||
export type MemberTier = Enums<'member_tier'>
|
||||
export type MemberRole = Enums<'member_role'>
|
||||
export type MemberStatus = Enums<'member_status'>
|
||||
export type TaskType = Enums<'task_type'>
|
||||
export type TaskStatus = Enums<'task_status'>
|
||||
export type TaskRecurrence = Enums<'recurrence_type'>
|
||||
export type ProjectStatus = Enums<'project_status'>
|
||||
export type KBVisibility = Enums<'kb_visibility'>
|
||||
export type ContactType = Enums<'contact_type'>
|
||||
export type PaymentPlatform = Enums<'payment_platform'>
|
||||
export type PaymentLinkStatus = Enums<'payment_link_status'>
|
||||
export type ChannelType = Enums<'channel_type'>
|
||||
export type AreaLeadStatus = Enums<'area_lead_status'>
|
||||
|
||||
Reference in New Issue
Block a user