diff --git a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/projects/OrganizationProjectsTable.tsx b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/projects/OrganizationProjectsTable.tsx index f81c30b3..0e19b9f3 100644 --- a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/projects/OrganizationProjectsTable.tsx +++ b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/projects/OrganizationProjectsTable.tsx @@ -26,7 +26,7 @@ import moment from 'moment'; import Link from 'next/link'; import { useEffect, useState } from 'react'; -type ProjectWithRepo = Tables<'projects'> & { repoName: string | null }; +type ProjectWithRepo = Tables<'projects'> & { repoFullName: string | null }; type Props = { projects: Tables<'projects'>[]; @@ -40,7 +40,7 @@ export function OrganizationProjectsTable({ projects }: Props) { const updatedProjects = await Promise.all( projects.map(async (project) => { const repoDetails = await getRepoDetails(project.repo_id); - return { ...project, repoName: repoDetails?.name ?? null }; + return { ...project, repoFullName: repoDetails?.repo_full_name ?? null }; }) ); setProjectsWithRepos(updatedProjects); @@ -79,8 +79,8 @@ export function OrganizationProjectsTable({ projects }: Props) {
- {row.original.repoName ? `${row.original.repoName.toLowerCase().replace(/\s+/g, '-').replace(/[A-Z]/g, (letter) => letter.toLowerCase())}` : ''} - {row.original.repoName && ((row.getValue('terraform_working_dir') as string) || '') ? '/' : ''} + {row.original.repoFullName ? `${row.original.repoFullName.toLowerCase().replace(/\s+/g, '-').replace(/[A-Z]/g, (letter) => letter.toLowerCase())}` : ''} + {row.original.repoFullName && ((row.getValue('terraform_working_dir') as string) || '') ? '/' : ''} {((row.getValue('terraform_working_dir') as string) || '').replace(/\s+/g, '-').replace(/[A-Z]/g, (letter) => letter.toLowerCase())}
diff --git a/src/components/CreateProjectForm.tsx b/src/components/CreateProjectForm.tsx index 2974fa08..44844942 100644 --- a/src/components/CreateProjectForm.tsx +++ b/src/components/CreateProjectForm.tsx @@ -1,20 +1,20 @@ 'use client' -import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; -import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; -import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { createProjectAction } from "@/data/user/projects"; import { useSAToastMutation } from "@/hooks/useSAToastMutation"; import { generateSlug } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; +import { GitHubLogoIcon } from "@radix-ui/react-icons"; import { motion } from "framer-motion"; -import { Check, Github } from "lucide-react"; +import { AlertCircle, Github } from "lucide-react"; +import Link from "next/link"; import { useRouter } from "next/navigation"; -import { useState } from 'react'; +import { FormEvent, useState } from 'react'; import { Controller, useForm } from "react-hook-form"; import { z } from "zod"; import { InputTags } from "./InputTags"; @@ -24,9 +24,8 @@ const MotionCard = motion(Card); const createProjectFormSchema = z.object({ name: z.string().min(1, "Project name is required"), - repository: z.number().int().positive("Repository ID must be a positive integer"), + repository: z.number().int().positive("Please select a repository"), terraformDir: z.string().min(1, "Terraform working directory is required"), - managedState: z.boolean(), labels: z.array(z.string()), }); @@ -34,7 +33,7 @@ type CreateProjectFormData = z.infer; type Repository = { id: number; - name: string; + repo_full_name: string | null; }; type CreateProjectFormProps = { @@ -43,16 +42,14 @@ type CreateProjectFormProps = { }; export default function CreateProjectForm({ organizationId, repositories }: CreateProjectFormProps) { - const [selectedRepo, setSelectedRepo] = useState(repositories[0]?.id || null); const router = useRouter(); - const { control, handleSubmit, setValue, watch } = useForm({ + const { control, handleSubmit, formState: { errors } } = useForm({ resolver: zodResolver(createProjectFormSchema), defaultValues: { name: "", repository: repositories[0]?.id || 0, terraformDir: "", - managedState: true, labels: [], }, }); @@ -66,7 +63,6 @@ export default function CreateProjectForm({ organizationId, repositories }: Crea slug, repoId: data.repository, terraformWorkingDir: data.terraformDir, - isManagingState: data.managedState, labels: data.labels, }); }, @@ -80,34 +76,30 @@ export default function CreateProjectForm({ organizationId, repositories }: Crea } }, }, - ); + ) + + + // isSubmitting is used to disable the submit button while the form is being submitted + const [isSubmitting, setIsSubmitting] = useState(false); const onSubmit = (data: CreateProjectFormData) => { + setIsSubmitting(true); createProjectMutation.mutate(data); }; + const handleFormSubmit = (e: FormEvent) => { + e.preventDefault(); + handleSubmit(onSubmit)(); + }; + return (
-
{ - e.preventDefault(); - handleSubmit(onSubmit)(e); - }}> - {/* {Object.entries(watch()).map(([key, value]) => ( -
- {key}: {JSON.stringify(value)} -
- ))} */} -
+ +
Create new Project Create a new project within your organization.
-
- - -
( - +
+ + {errors.name && ( +
+ + {errors.name.message} +
+ )} +
)} />
@@ -152,39 +152,54 @@ export default function CreateProjectForm({ organizationId, repositories }: Crea Select a repository Choose the repository for your project
- - - Connected to GitHub - - + + e.stopPropagation()} + > + + {repositories.length > 0 ? ( - -
- {repositories.map((repo, index) => ( - { - setSelectedRepo(repo.id); - setValue("repository", repo.id); - }} - initial={{ opacity: 0, y: 20 }} - animate={{ opacity: 1, y: 0 }} - transition={{ delay: index * 0.1 }} - > - - - {repo.name} - - - ))} -
- -
+ ( +
+ + {errors.repository && ( +
+ + {errors.repository.message} +
+ )} +
+ )} + /> ) : (
@@ -218,12 +233,20 @@ export default function CreateProjectForm({ organizationId, repositories }: Crea name="terraformDir" control={control} render={({ field }) => ( - +
+ + {errors.terraformDir && ( +
+ + {errors.terraformDir.message} +
+ )} +
)} />
@@ -244,20 +267,6 @@ export default function CreateProjectForm({ organizationId, repositories }: Crea
-
- ( - - )} - /> - -
+
+ + +
); diff --git a/src/components/CreateProjectForm2.tsx b/src/components/CreateProjectForm2.tsx deleted file mode 100644 index ff2ab727..00000000 --- a/src/components/CreateProjectForm2.tsx +++ /dev/null @@ -1,144 +0,0 @@ -'use client' - -import { Badge } from "@/components/ui/badge"; -import { Button } from "@/components/ui/button"; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; -import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; -import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; -import { motion } from "framer-motion"; -import { Check, Github, MonitorOff, Play, RotateCw } from "lucide-react"; -import { useState } from 'react'; -import { T } from "./ui/Typography"; -import { Separator } from "./ui/separator"; - -const MotionCard = motion(Card); - -export default function CreateProjectForm2({ organizationId }: { organizationId: string }) { - const [selectedRepo, setSelectedRepo] = useState(''); - const [autoQueueRun, setAutoQueueRun] = useState('apply-before-merge'); - - const repositories = [ - { id: 'repo1', name: 'Repository 1' }, - { id: 'repo2', name: 'Repository 2' }, - { id: 'repo3', name: 'Repository 3' }, - { id: 'repo4', name: 'Repository 4' }, - { id: 'repo5', name: 'Repository 5' }, - ]; - - return ( -
-
-
- Create new Project - Create a new project within your organization. -
-
- - -
-
- - - {/* -
- Project Details & Repository Selection - Provide project details and choose the repository -
-
*/} - - -
- - -
- -
- -
- -
-
- Select a repository - Choose the repository for your project -
- - - Connected to GitHub - - -
- - -
- {repositories.map((repo) => ( - setSelectedRepo(repo.id)} - > - - - {repo.name} - - - ))} -
- -
-
-
- - - -
- Terraform Configuration - Specify the working directory for Terraform -
-
- -
- - -
-
-
- - - -
- Auto Queue Runs - Configure when to automatically queue runs -
-
- -
- {[ - { id: 'apply-before-merge', label: 'Apply Before Merge', icon: Play }, - { id: 'apply-after-merge', label: 'Apply After Merge', icon: RotateCw }, - { id: 'never', label: 'Never', icon: MonitorOff }, - ].map((option) => ( - setAutoQueueRun(option.id)} - > - - - {option.label} -

- Provide information regarding your project. -

-
-
- ))} -
-
-
-
- ); -} \ No newline at end of file diff --git a/src/data/user/organizations.ts b/src/data/user/organizations.ts index 0bd3477e..c90cebe6 100644 --- a/src/data/user/organizations.ts +++ b/src/data/user/organizations.ts @@ -58,87 +58,94 @@ export const createOrganization = async ( isOnboardingFlow?: boolean; } = {}, ): Promise> => { - const supabaseClient = createSupabaseUserServerActionClient(); - const user = await serverGetLoggedInUser(); - - const organizationId = uuid(); - - if (RESTRICTED_SLUG_NAMES.includes(slug)) { - return { status: 'error', message: 'Slug is restricted' }; - } - - if (!SLUG_PATTERN.test(slug)) { - return { - status: 'error', - message: 'Slug does not match the required pattern', - }; - } - - const { error } = await supabaseClient.from('organizations').insert({ - title: name, - id: organizationId, - slug: slug, - }); + try { + const supabaseClient = createSupabaseUserServerActionClient(); + const user = await serverGetLoggedInUser(); - revalidatePath('/org/[organizationId]', 'layout'); + const organizationId = uuid(); - if (error) { - return { status: 'error', message: error.message }; - } + if (RESTRICTED_SLUG_NAMES.includes(slug)) { + return { status: 'error', message: 'Slug is restricted' }; + } - const { error: orgMemberErrors } = await supabaseAdminClient - .from('organization_members') - .insert([ - { - member_id: user.id, - organization_id: organizationId, - member_role: 'owner', - }, - ]); - - if (orgMemberErrors) { - return { status: 'error', message: orgMemberErrors.message }; - } + if (!SLUG_PATTERN.test(slug)) { + return { + status: 'error', + message: 'Slug does not match the required pattern', + }; + } - if (isOnboardingFlow) { - // insert 3 dummy projects - const { error: updateError } = await supabaseClient - .from('user_private_info') - .update({ default_organization: organizationId }) - .eq('id', user.id); + const { error: insertError } = await supabaseClient + .from('organizations') + .insert({ + title: name, + id: organizationId, + slug: slug, + }); + + if (insertError) { + console.error('Error inserting organization:', insertError); + return { status: 'error', message: insertError.message }; + } - console.log('updateError', updateError); - if (updateError) { - return { status: 'error', message: updateError.message }; + const { error: orgMemberErrors } = await supabaseAdminClient + .from('organization_members') + .insert([ + { + member_id: user.id, + organization_id: organizationId, + member_role: 'owner', + }, + ]); + + if (orgMemberErrors) { + console.error('Error inserting organization member:', orgMemberErrors); + return { status: 'error', message: orgMemberErrors.message }; } - const updateUserMetadataPayload: Partial = { - onboardingHasCreatedOrganization: true, - }; + if (isOnboardingFlow) { + const { error: updateError } = await supabaseClient + .from('user_private_info') + .update({ default_organization: organizationId }) + .eq('id', user.id); - const updateUserMetadataResponse = await supabaseClient.auth.updateUser({ - data: updateUserMetadataPayload, - }); + if (updateError) { + console.error('Error updating user private info:', updateError); + return { status: 'error', message: updateError.message }; + } - if (updateUserMetadataResponse.error) { - return { - status: 'error', - message: updateUserMetadataResponse.error.message, + const updateUserMetadataPayload: Partial = { + onboardingHasCreatedOrganization: true, }; - } - const refreshSessionResponse = await refreshSessionAction(); - if (refreshSessionResponse.status === 'error') { - return refreshSessionResponse; + const updateUserMetadataResponse = await supabaseClient.auth.updateUser({ + data: updateUserMetadataPayload, + }); + + if (updateUserMetadataResponse.error) { + console.error( + 'Error updating user metadata:', + updateUserMetadataResponse.error, + ); + return { + status: 'error', + message: updateUserMetadataResponse.error.message, + }; + } + + const refreshSessionResponse = await refreshSessionAction(); + if (refreshSessionResponse.status === 'error') { + console.error('Error refreshing session:', refreshSessionResponse); + return refreshSessionResponse; + } } - throw new Error('failed'); + revalidatePath('/org/[organizationId]', 'layout'); + return { status: 'success', data: slug }; + } catch (error) { + console.error('Unexpected error in createOrganization:', error); + return { status: 'error', message: 'An unexpected error occurred' }; } - - return { - status: 'success', - data: slug, - }; }; export async function fetchSlimOrganizations() { diff --git a/src/data/user/projects.tsx b/src/data/user/projects.tsx index 02055915..fddc50b5 100644 --- a/src/data/user/projects.tsx +++ b/src/data/user/projects.tsx @@ -68,7 +68,6 @@ export const createProjectAction = async ({ slug, repoId, terraformWorkingDir, - isManagingState, labels, }: { organizationId: string; @@ -76,7 +75,6 @@ export const createProjectAction = async ({ slug: string; repoId: number; terraformWorkingDir: string; - isManagingState: boolean; labels: string[]; }): Promise>> => { "use server"; @@ -89,7 +87,7 @@ export const createProjectAction = async ({ slug, repo_id: repoId, terraform_working_dir: terraformWorkingDir, - is_managing_state: isManagingState, + is_managing_state: true, is_in_main_branch: true, is_generated: true, project_status: "draft", diff --git a/src/data/user/repos.ts b/src/data/user/repos.ts index 45e98862..a9da7001 100644 --- a/src/data/user/repos.ts +++ b/src/data/user/repos.ts @@ -6,7 +6,7 @@ export async function getRepoDetails(repoId: number) { const supabaseClient = createSupabaseUserServerComponentClient(); const { data, error } = await supabaseClient .from('repos') - .select('id, name') + .select('id, repo_full_name') .eq('id', repoId) .single(); @@ -21,7 +21,7 @@ export async function getOrganizationRepos(organizationId: string) { const supabaseClient = createSupabaseUserServerComponentClient(); const { data, error } = await supabaseClient .from('repos') - .select('id, name') + .select('id, repo_full_name') .eq('organization_id', organizationId); if (error) { diff --git a/src/lib/database.types.ts b/src/lib/database.types.ts index 1ba527e4..9df11e54 100644 --- a/src/lib/database.types.ts +++ b/src/lib/database.types.ts @@ -2,7 +2,7 @@ export type Json = | string | number | boolean - | null + | null | { [key: string]: Json | undefined } | Json[] @@ -94,6 +94,505 @@ export type Database = { }, ] } + digger_batches: { + Row: { + batch_type: string + branch_name: string + comment_id: number | null + digger_config: string | null + github_installation_id: number | null + gitlab_project_id: number | null + id: string + pr_number: number | null + repo_full_name: string + repo_name: string + repo_owner: string + source_details: string | null + status: number + vcs: string | null + } + Insert: { + batch_type: string + branch_name: string + comment_id?: number | null + digger_config?: string | null + github_installation_id?: number | null + gitlab_project_id?: number | null + id?: string + pr_number?: number | null + repo_full_name: string + repo_name: string + repo_owner: string + source_details?: string | null + status: number + vcs?: string | null + } + Update: { + batch_type?: string + branch_name?: string + comment_id?: number | null + digger_config?: string | null + github_installation_id?: number | null + gitlab_project_id?: number | null + id?: string + pr_number?: number | null + repo_full_name?: string + repo_name?: string + repo_owner?: string + source_details?: string | null + status?: number + vcs?: string | null + } + Relationships: [] + } + digger_job_parent_links: { + Row: { + created_at: string | null + deleted_at: string | null + digger_job_id: string | null + id: number + parent_digger_job_id: string | null + updated_at: string | null + } + Insert: { + created_at?: string | null + deleted_at?: string | null + digger_job_id?: string | null + id?: number + parent_digger_job_id?: string | null + updated_at?: string | null + } + Update: { + created_at?: string | null + deleted_at?: string | null + digger_job_id?: string | null + id?: number + parent_digger_job_id?: string | null + updated_at?: string | null + } + Relationships: [] + } + digger_job_summaries: { + Row: { + created_at: string + deleted_at: string | null + id: string + resources_created: number + resources_deleted: number + resources_updated: number + updated_at: string + } + Insert: { + created_at?: string + deleted_at?: string | null + id?: string + resources_created?: number + resources_deleted?: number + resources_updated?: number + updated_at?: string + } + Update: { + created_at?: string + deleted_at?: string | null + id?: string + resources_created?: number + resources_deleted?: number + resources_updated?: number + updated_at?: string + } + Relationships: [] + } + digger_job_tokens: { + Row: { + created_at: string | null + deleted_at: string | null + expiry: string | null + id: number + organisation_id: number | null + type: string | null + updated_at: string | null + value: string | null + } + Insert: { + created_at?: string | null + deleted_at?: string | null + expiry?: string | null + id?: number + organisation_id?: number | null + type?: string | null + updated_at?: string | null + value?: string | null + } + Update: { + created_at?: string | null + deleted_at?: string | null + expiry?: string | null + id?: number + organisation_id?: number | null + type?: string | null + updated_at?: string | null + value?: string | null + } + Relationships: [] + } + digger_jobs: { + Row: { + batch_id: string + created_at: string + deleted_at: string | null + digger_job_id: string + digger_job_summary_id: string | null + id: string + job_spec: string | null + plan_footprint: string | null + pr_comment_url: string | null + status: number + status_updated_at: string | null + terraform_output: string | null + updated_at: string + workflow_file: string | null + workflow_run_url: string | null + } + Insert: { + batch_id: string + created_at?: string + deleted_at?: string | null + digger_job_id: string + digger_job_summary_id?: string | null + id?: string + job_spec?: string | null + plan_footprint?: string | null + pr_comment_url?: string | null + status: number + status_updated_at?: string | null + terraform_output?: string | null + updated_at?: string + workflow_file?: string | null + workflow_run_url?: string | null + } + Update: { + batch_id?: string + created_at?: string + deleted_at?: string | null + digger_job_id?: string + digger_job_summary_id?: string | null + id?: string + job_spec?: string | null + plan_footprint?: string | null + pr_comment_url?: string | null + status?: number + status_updated_at?: string | null + terraform_output?: string | null + updated_at?: string + workflow_file?: string | null + workflow_run_url?: string | null + } + Relationships: [ + { + foreignKeyName: "fk_digger_jobs_batch" + columns: ["batch_id"] + isOneToOne: false + referencedRelation: "digger_batches" + referencedColumns: ["id"] + }, + { + foreignKeyName: "fk_digger_jobs_digger_job_summary" + columns: ["digger_job_summary_id"] + isOneToOne: false + referencedRelation: "digger_job_summaries" + referencedColumns: ["id"] + }, + ] + } + digger_locks: { + Row: { + created_at: string + deleted_at: string | null + id: string + lock_id: number + organization_id: string + resource: string + updated_at: string + } + Insert: { + created_at?: string + deleted_at?: string | null + id?: string + lock_id: number + organization_id: string + resource: string + updated_at?: string + } + Update: { + created_at?: string + deleted_at?: string | null + id?: string + lock_id?: number + organization_id?: string + resource?: string + updated_at?: string + } + Relationships: [ + { + foreignKeyName: "fk_digger_locks_organization" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + ] + } + digger_run_queue_items: { + Row: { + created_at: string | null + deleted_at: string | null + digger_run_id: number | null + id: number + project_id: number | null + updated_at: string | null + } + Insert: { + created_at?: string | null + deleted_at?: string | null + digger_run_id?: number | null + id?: number + project_id?: number | null + updated_at?: string | null + } + Update: { + created_at?: string | null + deleted_at?: string | null + digger_run_id?: number | null + id?: number + project_id?: number | null + updated_at?: string | null + } + Relationships: [] + } + digger_run_stages: { + Row: { + batch_id: string + created_at: string + deleted_at: string | null + id: string + updated_at: string + } + Insert: { + batch_id: string + created_at?: string + deleted_at?: string | null + id?: string + updated_at?: string + } + Update: { + batch_id?: string + created_at?: string + deleted_at?: string | null + id?: string + updated_at?: string + } + Relationships: [ + { + foreignKeyName: "fk_digger_run_stages_batch" + columns: ["batch_id"] + isOneToOne: false + referencedRelation: "digger_batches" + referencedColumns: ["id"] + }, + ] + } + digger_runs: { + Row: { + apply_stage_id: string | null + approval_author: string | null + approval_date: string | null + commit_id: string + created_at: string + deleted_at: string | null + digger_config: string | null + github_installation_id: number | null + id: string + is_approved: boolean | null + plan_stage_id: string | null + pr_number: number | null + project_name: string | null + repo_id: number + run_type: string + status: string + triggertype: string + updated_at: string + } + Insert: { + apply_stage_id?: string | null + approval_author?: string | null + approval_date?: string | null + commit_id: string + created_at?: string + deleted_at?: string | null + digger_config?: string | null + github_installation_id?: number | null + id?: string + is_approved?: boolean | null + plan_stage_id?: string | null + pr_number?: number | null + project_name?: string | null + repo_id?: number + run_type: string + status: string + triggertype: string + updated_at?: string + } + Update: { + apply_stage_id?: string | null + approval_author?: string | null + approval_date?: string | null + commit_id?: string + created_at?: string + deleted_at?: string | null + digger_config?: string | null + github_installation_id?: number | null + id?: string + is_approved?: boolean | null + plan_stage_id?: string | null + pr_number?: number | null + project_name?: string | null + repo_id?: number + run_type?: string + status?: string + triggertype?: string + updated_at?: string + } + Relationships: [ + { + foreignKeyName: "fk_digger_runs_apply_stage" + columns: ["apply_stage_id"] + isOneToOne: false + referencedRelation: "digger_run_stages" + referencedColumns: ["id"] + }, + { + foreignKeyName: "fk_digger_runs_plan_stage" + columns: ["plan_stage_id"] + isOneToOne: false + referencedRelation: "digger_run_stages" + referencedColumns: ["id"] + }, + { + foreignKeyName: "fk_digger_runs_repo" + columns: ["repo_id"] + isOneToOne: false + referencedRelation: "repos" + referencedColumns: ["id"] + }, + ] + } + github_app_installation_links: { + Row: { + created_at: string + deleted_at: string | null + github_installation_id: number + id: string + organization_id: string + status: number + updated_at: string + } + Insert: { + created_at?: string + deleted_at?: string | null + github_installation_id: number + id?: string + organization_id: string + status: number + updated_at?: string + } + Update: { + created_at?: string + deleted_at?: string | null + github_installation_id?: number + id?: string + organization_id?: string + status?: number + updated_at?: string + } + Relationships: [ + { + foreignKeyName: "fk_github_app_installation_links_organization" + columns: ["organization_id"] + isOneToOne: false + referencedRelation: "organizations" + referencedColumns: ["id"] + }, + ] + } + github_app_installations: { + Row: { + account_id: number + created_at: string + deleted_at: string | null + github_app_id: number + github_installation_id: number + id: string + login: string + repo: string | null + status: number + updated_at: string + } + Insert: { + account_id: number + created_at?: string + deleted_at?: string | null + github_app_id: number + github_installation_id: number + id?: string + login: string + repo?: string | null + status: number + updated_at?: string + } + Update: { + account_id?: number + created_at?: string + deleted_at?: string | null + github_app_id?: number + github_installation_id?: number + id?: string + login?: string + repo?: string | null + status?: number + updated_at?: string + } + Relationships: [] + } + github_apps: { + Row: { + created_at: string + deleted_at: string | null + github_app_url: string + github_id: number + id: string + name: string + updated_at: string + } + Insert: { + created_at?: string + deleted_at?: string | null + github_app_url: string + github_id: number + id?: string + name: string + updated_at?: string + } + Update: { + created_at?: string + deleted_at?: string | null + github_app_url?: string + github_id?: number + id?: string + name?: string + updated_at?: string + } + Relationships: [] + } internal_blog_author_posts: { Row: { author_id: string @@ -765,6 +1264,10 @@ export type Database = { id: number name: string organization_id: string | null + repo_full_name: string | null + repo_name: string | null + repo_organisation: string | null + repo_url: string | null updated_at: string | null } Insert: { @@ -774,6 +1277,10 @@ export type Database = { id?: number name: string organization_id?: string | null + repo_full_name?: string | null + repo_name?: string | null + repo_organisation?: string | null + repo_url?: string | null updated_at?: string | null } Update: { @@ -783,6 +1290,10 @@ export type Database = { id?: number name?: string organization_id?: string | null + repo_full_name?: string | null + repo_name?: string | null + repo_organisation?: string | null + repo_url?: string | null updated_at?: string | null } Relationships: [ @@ -1559,6 +2070,10 @@ export type Database = { updated_at: string }[] } + operation: { + Args: Record + Returns: string + } search: { Args: { prefix: string diff --git a/src/middleware.ts b/src/middleware.ts index 079daa69..b764838e 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -48,6 +48,7 @@ function shouldOnboardUser(pathname: string, user: User | undefined) { const matchOnboarding = match(onboardingPaths); const isOnboardingRoute = matchOnboarding(pathname); if (!isUnprotectedPage(pathname) && user && !isOnboardingRoute) { + console.log('user is not onboarded reason : ', user); const userMetadata = authUserMetadataSchema.parse(user.user_metadata); const { onboardingHasAcceptedTerms, @@ -59,9 +60,13 @@ function shouldOnboardUser(pathname: string, user: User | undefined) { !onboardingHasCompletedProfile || !onboardingHasCreatedOrganization ) { + console.log( + `user is not onboarded reason : onboardingHasAcceptedTerms : ${userMetadata.onboardingHasAcceptedTerms} onboardingHasCompletedProfile : ${userMetadata.onboardingHasCompletedProfile} onboardingHasCreatedOrganization : ${userMetadata.onboardingHasCreatedOrganization}`, + ); return true; } } + console.log('user is onboarded'); return false; }