From 140160c5060769f2a4b78d8fbbe6817d8b354124 Mon Sep 17 00:00:00 2001 From: nael Date: Sun, 21 Apr 2024 01:37:07 +0200 Subject: [PATCH] :bug: Fix projects creation --- .../client-ts/src/components/Nav/user-nav.tsx | 27 ++++++++++++------- .../src/components/shared/team-switcher.tsx | 4 +-- apps/client-ts/src/hooks/useProfile.tsx | 2 +- packages/api/prisma/schema.prisma | 24 ++++++++++------- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/apps/client-ts/src/components/Nav/user-nav.tsx b/apps/client-ts/src/components/Nav/user-nav.tsx index 7eb14c9f2..e4c2dca77 100644 --- a/apps/client-ts/src/components/Nav/user-nav.tsx +++ b/apps/client-ts/src/components/Nav/user-nav.tsx @@ -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"; @@ -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]); @@ -61,7 +68,7 @@ export function UserNav() {

- {profile ? profile.first_name || profile.email : isLoading ? : "No mail found"} + {profile ? profile.email || profile.first_name : isLoading ? : "No mail found"}

diff --git a/apps/client-ts/src/components/shared/team-switcher.tsx b/apps/client-ts/src/components/shared/team-switcher.tsx index f7d67946a..5b734aec8 100644 --- a/apps/client-ts/src/components/shared/team-switcher.tsx +++ b/apps/client-ts/src/components/shared/team-switcher.tsx @@ -189,8 +189,8 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { { - config.DISTRIBUTION == "managed" && ( -

USER TO DISPLAY

+ config.DISTRIBUTION === "managed" && ( +

{profile ? profile.email : "no profile"}

) } diff --git a/apps/client-ts/src/hooks/useProfile.tsx b/apps/client-ts/src/hooks/useProfile.tsx index adad00939..bac61afa2 100644 --- a/apps/client-ts/src/hooks/useProfile.tsx +++ b/apps/client-ts/src/hooks/useProfile.tsx @@ -5,7 +5,7 @@ import { users as User } from 'api'; const useProfile = (stytchUserId: string) => { return useQuery({ queryKey: ['profile', stytchUserId], - queryFn: async (): Promise => { + queryFn: async (): Promise => { const response = await fetch(`${config.API_URL}/auth/users/${stytchUserId}`); if (!response.ok) { throw new Error('Network response was not ok'); diff --git a/packages/api/prisma/schema.prisma b/packages/api/prisma/schema.prisma index ff8bb5b14..adde91bb6 100644 --- a/packages/api/prisma/schema.prisma +++ b/packages/api/prisma/schema.prisma @@ -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 { @@ -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") @@ -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