-
- (
-
- )}
- />
-
-
+
+
+
+
);
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;
}