Skip to content

Commit

Permalink
🐛 Fix projects creation
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Apr 20, 2024
1 parent be9a9b2 commit 140160c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
27 changes: 17 additions & 10 deletions apps/client-ts/src/components/Nav/user-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { Skeleton } from "@/components/ui/skeleton";
import useProfile from "@/hooks/useProfile";
import useProfileStore from "@/state/profileStore";
import { useStytchUser,useStytch } from "@stytch/nextjs";
import { useStytchUser, useStytch } from "@stytch/nextjs";
import { useRouter } from "next/navigation";
import Link from "next/link";
import { useEffect } from "react";
Expand All @@ -25,20 +25,27 @@ export function UserNav() {
const stytch = useStytch();
const { user } = useStytchUser();
const router = useRouter();
const {data, isLoading} = useProfile(user?.user_id!);
if(!data) {
const {data, isLoading, isError, error} = useProfile(user?.user_id!);
if(isLoading) {
console.log("loading profiles");
}
if(data) {
console.log("data is there ");
}
if(isError){
console.log('Profiles fetch error: '+ error)
}
const { profile, setProfile } = useProfileStore();

useEffect(()=> {
if(data && data.length > 0 ){
if(data){
console.log("data is "+ JSON.stringify(data));
setProfile({
id_user: data[0].id_user,
email: data[0].email!,
first_name: data[0].first_name,
last_name: data[0].last_name,
//id_organization: data[0].id_organization as string,
id_user: data.id_user,
email: data.email!,
first_name: data.first_name,
last_name: data.last_name,
//id_organization: data.id_organization as string,
})
}
}, [data, setProfile]);
Expand All @@ -61,7 +68,7 @@ export function UserNav() {
<DropdownMenuLabel className="font-normal">
<div className="flex flex-col space-y-1">
<p className="text-xs leading-none text-muted-foreground">
{profile ? profile.first_name || profile.email : isLoading ? <Skeleton className="w-[100px] h-[20px] rounded-md" /> : "No mail found"}
{profile ? profile.email || profile.first_name : isLoading ? <Skeleton className="w-[100px] h-[20px] rounded-md" /> : "No mail found"}
</p>
</div>
</DropdownMenuLabel>
Expand Down
4 changes: 2 additions & 2 deletions apps/client-ts/src/components/shared/team-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) {
<CommandList>
<CommandGroup>
{
config.DISTRIBUTION == "managed" && (
<h4>USER TO DISPLAY</h4>
config.DISTRIBUTION === "managed" && (
<h4>{profile ? profile.email : "no profile"}</h4>
)
}
<DialogTrigger asChild>
Expand Down
2 changes: 1 addition & 1 deletion apps/client-ts/src/hooks/useProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { users as User } from 'api';
const useProfile = (stytchUserId: string) => {
return useQuery({
queryKey: ['profile', stytchUserId],
queryFn: async (): Promise<User[]> => {
queryFn: async (): Promise<User> => {
const response = await fetch(`${config.API_URL}/auth/users/${stytchUserId}`);
if (!response.ok) {
throw new Error('Network response was not ok');
Expand Down
24 changes: 15 additions & 9 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ model webhooks_reponses {

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
model connection_strategies {
id_connection_strategy String @id(map: "pk_connection_strategies") @db.Uuid
id_connection_strategy String @id(map: "pk_connection_strategies") @db.Uuid
status Boolean
type String
id_project String? @db.Uuid
id_project String? @db.Uuid
cs_entities cs_entities[]
}

model tcg_collections {
Expand Down Expand Up @@ -170,9 +171,9 @@ model connections {
expiration_timestamp DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
connection_token String?
vertical String
id_project String @db.Uuid
id_linked_user String @db.Uuid
vertical String?
linked_users linked_users @relation(fields: [id_linked_user], references: [id_linked_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_11")
projects projects @relation(fields: [id_project], references: [id_project], onDelete: NoAction, onUpdate: NoAction, map: "fk_9")
Expand Down Expand Up @@ -413,21 +414,26 @@ model crm_users {
}

model cs_attributes {
id_cs_attribute String @id(map: "pk_ct_attributes") @db.Uuid
id_cs_attribute String @id(map: "pk_ct_attributes") @db.Uuid
attribute_slug String
data_type String
id_cs_entity String @db.Uuid
id_cs_entity String @db.Uuid
cs_entities cs_entities @relation(fields: [id_cs_entity], references: [id_cs_entity], onDelete: NoAction, onUpdate: NoAction, map: "fk_cs_entity")
cs_values cs_values[]
}

model cs_entities {
id_cs_entity String @id(map: "pk_ct_entities") @db.Uuid
id_connection_strategy String @db.Uuid
id_cs_entity String @id(map: "pk_ct_entities") @db.Uuid
id_connection_strategy String @db.Uuid
cs_attributes cs_attributes[]
connection_strategies connection_strategies @relation(fields: [id_connection_strategy], references: [id_connection_strategy], onDelete: NoAction, onUpdate: NoAction, map: "fk_cs_id")
}

model cs_values {
id_cs_value String @id(map: "pk_ct_values") @db.Uuid
id_cs_value String @id(map: "pk_ct_values") @db.Uuid
value String
id_cs_attribute String @db.Uuid
id_cs_attribute String @db.Uuid
cs_attributes cs_attributes @relation(fields: [id_cs_attribute], references: [id_cs_attribute], onDelete: NoAction, onUpdate: NoAction, map: "fk_cs_attribute")
}

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
Expand Down

0 comments on commit 140160c

Please sign in to comment.