Skip to content

Commit

Permalink
fix org flow
Browse files Browse the repository at this point in the history
  • Loading branch information
motatoes committed Nov 20, 2024
1 parent 883fd7e commit 2f608ec
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default async function OrganizationProjectsNavbar({
}: {
params: unknown;
}) {

console.log("in catchall", params)
const { organizationId } = organizationParamSchema.parse(params);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ function getAllFlowStates(onboardingStatus: AuthUserMetadata): FLOW_STATE[] {
if (isUserCreatedThroughOrgInvitation) {
flowStates.push("JOIN_INVITED_ORG");
} else {
flowStates.push("ORGANIZATION");
if (process.env.NEXT_PUBLIC_SKIP_ORG_CREATION !== "true") {
flowStates.push("ORGANIZATION");
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CreateOrganizationSchema, createOrganizationSchema } from "@/utils/zod-
import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation } from "@tanstack/react-query";
import Cookies from 'js-cookie';
import { useEffect } from "react";
import { useForm } from "react-hook-form";

type OrganizationCreationProps = {
Expand All @@ -22,19 +21,11 @@ export function OrganizationCreation({ onSuccess }: OrganizationCreationProps) {
resolver: zodResolver(createOrganizationSchema),
});

useEffect(() => {
if (process.env.NEXT_PUBLIC_SKIP_ORG_CREATION === "true") {
createOrgMutation.mutate({ "organizationTitle": "digger", organizationSlug: "digger" });
}
}, [onSuccess])

const createOrgMutation = useMutation({
mutationFn: async ({ organizationTitle, organizationSlug }: CreateOrganizationSchema) => {
if (process.env.NEXT_PUBLIC_SKIP_ORG_CREATION === "true") {
return createOrganization(organizationTitle, organizationSlug, { isOnboardingFlow: true, ignoreIfOrgExists: true })
} else {
return createOrganization(organizationTitle, organizationSlug, { isOnboardingFlow: true })
}
return createOrganization(organizationTitle, organizationSlug, { isOnboardingFlow: true })

},
onSuccess: (data) => {
const { data: orgId } = data as { data: string }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { T } from "@/components/ui/Typography";
import { useToast } from "@/components/ui/use-toast";
import { createOrganization } from "@/data/user/organizations";
import { updateUserProfileNameAndAvatar, uploadPublicUserAvatar } from "@/data/user/user";
import { generateSlug } from "@/lib/utils";
import { getUserAvatarUrl } from "@/utils/helpers";
Expand Down Expand Up @@ -38,6 +39,13 @@ export function ProfileUpdate({
mutationFn: () => updateUserProfileNameAndAvatar({ fullName, userName, avatarUrl }, { isOnboardingFlow: true }),
onSuccess: () => {
toast({ title: "Profile updated!", description: "Your profile has been successfully updated." });

// TODO: move this to server side component /src/app/(dynamic-pages)/(authenticated-pages)/onboarding/page.tsx
if (process.env.NEXT_PUBLIC_SKIP_ORG_CREATION === "true") {
console.log("creating default organisation for user")
createOrganization("digger", "digger", { isOnboardingFlow: true, ignoreIfOrgExists: true })
}

onSuccess();
},
onError: () => {
Expand Down
13 changes: 8 additions & 5 deletions src/data/user/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { v4 as uuidv4 } from 'uuid';
import { refreshSessionAction } from './session';
import { updateUserProfileMetadata } from './user';


export const getOrganizationIdBySlug = async (slug: string) => {
const supabaseClient = createSupabaseUserServerComponentClient();

Expand Down Expand Up @@ -91,11 +90,10 @@ export const createOrganization = async (
// if set we simply get the org if it already exists
if (ignoreIfOrgExists) {
try {
organizationId = await getOrganizationIdBySlug(slug)
} catch(fetchError) {
organizationId = await getOrganizationIdBySlug(slug);
} catch (fetchError) {
return { status: 'error', message: fetchError.message };
}

} else {
return { status: 'error', message: insertError.message };
}
Expand Down Expand Up @@ -155,7 +153,6 @@ export const createOrganization = async (
}
};


export async function fetchSlimOrganizations() {
const currentUser = await serverGetLoggedInUser();
const supabaseClient = createSupabaseUserServerComponentClient();
Expand Down Expand Up @@ -282,6 +279,12 @@ export const getLoggedInUserOrganizationRole = async (
.single();

if (error) {
console.log(
'error in getloggedinUserOrganizationRole:',
userId,
organizationId,
error,
);
throw error;
} else if (!data) {
throw new Error('User is not a member of this organization');
Expand Down

0 comments on commit 2f608ec

Please sign in to comment.