Skip to content

Commit

Permalink
tmp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
motatoes committed Nov 19, 2024
1 parent 2b9d09e commit 421d8fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { useToast } from "@/components/ui/use-toast";
import { createOrganization } from "@/data/user/organizations";
import { createOrganization, setUserMetaDataWithOrgCreated } from "@/data/user/organizations";
import { generateOrganizationSlug } from "@/lib/utils";
import { CreateOrganizationSchema, createOrganizationSchema } from "@/utils/zod-schemas/organization";
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 @@ -21,6 +22,14 @@ export function OrganizationCreation({ onSuccess }: OrganizationCreationProps) {
resolver: zodResolver(createOrganizationSchema),
});

useEffect(() => {
if (process.env.NEXT_PUBLIC_SKIP_ORG_CREATION === "true") {
setUserMetaDataWithOrgCreated()
onSuccess()
return
}
}, [onSuccess])

const createOrgMutation = useMutation({
mutationFn: async ({ organizationTitle, organizationSlug }: CreateOrganizationSchema) => {
return createOrganization(organizationTitle, organizationSlug, { isOnboardingFlow: true })
Expand Down
23 changes: 23 additions & 0 deletions src/data/user/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import type {
UnwrapPromise,
} from '@/types';
import { serverGetLoggedInUser } from '@/utils/server/serverGetLoggedInUser';
import type { AuthUserMetadata } from '@/utils/zod-schemas/authUserMetadata';
import { revalidatePath } from 'next/cache';
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 @@ -142,6 +144,27 @@ export const createOrganization = async (
}
};

export const setUserMetaDataWithOrgCreated = async () => {
const supabaseClient = createSupabaseUserServerComponentClient();
const user = await serverGetLoggedInUser();
const updateUserMetadataPayload: Partial<AuthUserMetadata> = {
onboardingHasCreatedOrganization: true,
};

const updateUserMetadataResponse = await supabaseClient.auth.updateUser({
data: updateUserMetadataPayload,
});

if (updateUserMetadataResponse.error) {
console.error(
'Error updating user metadata:',
updateUserMetadataResponse.error,
);

throw updateUserMetadataResponse.error;
}
};

export async function fetchSlimOrganizations() {
const currentUser = await serverGetLoggedInUser();
const supabaseClient = createSupabaseUserServerComponentClient();
Expand Down

0 comments on commit 421d8fd

Please sign in to comment.