om3r
om3r
TTCTheo's Typesafe Cult
Created by om3r on 4/17/2024 in #questions
how to pass trpc typescript between parent and children ?
I have data types when using useQuery but I want to also include these types inside the component that I am using here is an example const { data , isLoading, refetch } = api.users.submission.useQuery(undefined, { refetchOnWindowFocus: false }); <Submissions refetch={refetch} data={data} /> export default function Submission({refetch,data}) {} I want when I use data into Submission component I can see the data types that comes from useQuery, how can I achieve that ?
7 replies
TTCTheo's Typesafe Cult
Created by om3r on 1/23/2024 in #questions
prisma foreign key constraint error after merging user & admin into 1 table
I was handling authorization like this that i make a model for users and model for admin and each one has an email and password but now i am trying to refactor my code by merging users and admin into 1 table and handle auths like below model all_users { id String @id @default(uuid()) name String email String @unique(map: "user_email_key") password String role String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt user user? admin admin? } model user{ id String? alluserId String? @unique user all_users ? @relation(fields: [userId], references: [id]) votes votes[] } model admin{ id String? alluserId String? @unique user all_users ? @relation(fields: [userId], references: [id]) votes votes[] } model votes{ id String @id @default(uuid()) votes Json? user user @relation(fields: [userId], references: [alluserId]) userId String admin admin @relation(fields: [adminId], references: [alluserId]) adminId String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([entrepreneurId], name: "index_votes") } but now when I try to make npx prisma db push so I can use votes i always get this error insert or update on table "votes" violates foreign key constraint "votes_userId_fkey" 0: sql_schema_connector::apply_migration::migration_step I am not sure why this happens , therefor prisma has no errors.
1 replies
TTCTheo's Typesafe Cult
Created by om3r on 1/8/2024 in #questions
How can I api useQuery when calling a function?
const { data: allData, isLoading } = api.admin.limitAccess.useQuery( {first,rows}, { refetchOnWindowFocus: false } I am using useQuery to fetch first , rows depends on a pagination but I have a button to click so I can download all the data from the query so I want to use it like this const exportCSV = async () => { try { const response = await api.admin.limitAccess.useQuery({ first: 0, rows: totalRecords }); setAllData(response?.data); tableRef?.current?.exportCSV(); } catch (error) { console.error("Error exporting CSV:", error); } }; but when I use something like this I get an error , why I cannot use the api inside a function ? Error exporting CSV: Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app
10 replies
TTCTheo's Typesafe Cult
Created by om3r on 11/15/2023 in #questions
uploading files locally
Its my first time using T3 stack about a month now and when it comes to upload files to my local server I got stuck for days I used to use multer to upload files but It didn't work for me so I used formidable and it worked but I have alot of issues handling file size to tell user his errors , also to handle specific file for uploads , also when I send the error to the user it keeps also uploading the file even if the user got error please need help on what to do and what is best, should I use formidable or is there anything else that T3 stack specify ? and this is my code just incase someone can tell me what is wrong.
6 replies
TTCTheo's Typesafe Cult
Created by om3r on 10/9/2023 in #questions
Uploading Files in T3-Stack
I have a question , I got a project from someone that used T3-Stack to upload files to the database but he made a big mistake and uploaded base64 to the database ( postgres with prisma ) but I want to upload multiple files to the server instead of uploading it via base64, how can i achieve this , I tried to find a way to use multer but I cannot please I need help also can I convert base64 files from database and save it as a string values and then fetch it with next js frontend ? please explain like I am a noob because its my first time using T3-Stack and everything is confusing to me
8 replies