rocawear
rocawear
Explore posts from servers
TTCTheo's Typesafe Cult
Created by aditya on 3/19/2024 in #questions
create t3-app not working
No description
6 replies
TTCTheo's Typesafe Cult
Created by aditya on 3/19/2024 in #questions
create t3-app not working
pn? (never seen thats why interested)
6 replies
TTCTheo's Typesafe Cult
Created by TayyabCodes on 12/22/2023 in #questions
Problem with react-hook-form
so you want people to guess since you are not providing code?
22 replies
TTCTheo's Typesafe Cult
Created by TayyabCodes on 12/22/2023 in #questions
Problem with react-hook-form
I would start by showing code, impossible to debug without any information
22 replies
TTCTheo's Typesafe Cult
Created by rocawear on 12/8/2023 in #questions
react hook form filters
Not sure how to trigger page push after value changes, also now if I submit with button it will reset my form
4 replies
TTCTheo's Typesafe Cult
Created by rocawear on 12/8/2023 in #questions
react hook form filters
Page:
export const filtersSchema = z.object({
example: z.string().nullable(),
example2: z.string().nullable(),
})

const ExamplePage: NextPage = () => {
const { control, values, update } = useFilters({
schema: filtersSchema,
defaultValues: {
example: null,
example2: null,
},
})

return (
<PageContainer>
<form onSubmit={update}>
<Select
title="title"
placeholder="placeholder"
control={control}
label="example"
options={[
{ label: "option 1", value: "option 1" },
{ label: "option 2", value: "option 2" },
{ label: "option 3", value: "option 3" },
]}
/>
<Select
title="title"
placeholder="placeholder"
control={control}
label="example2"
options={[
{ label: "option 1", value: "option 1" },
{ label: "option 2", value: "option 2" },
{ label: "option 3", value: "option 3" },
]}
/>
<Button type="submit">submit</Button>
</form>
{JSON.stringify(values, null, 2)}
</PageContainer>
)
}
export const filtersSchema = z.object({
example: z.string().nullable(),
example2: z.string().nullable(),
})

const ExamplePage: NextPage = () => {
const { control, values, update } = useFilters({
schema: filtersSchema,
defaultValues: {
example: null,
example2: null,
},
})

return (
<PageContainer>
<form onSubmit={update}>
<Select
title="title"
placeholder="placeholder"
control={control}
label="example"
options={[
{ label: "option 1", value: "option 1" },
{ label: "option 2", value: "option 2" },
{ label: "option 3", value: "option 3" },
]}
/>
<Select
title="title"
placeholder="placeholder"
control={control}
label="example2"
options={[
{ label: "option 1", value: "option 1" },
{ label: "option 2", value: "option 2" },
{ label: "option 3", value: "option 3" },
]}
/>
<Button type="submit">submit</Button>
</form>
{JSON.stringify(values, null, 2)}
</PageContainer>
)
}
Hook:
type UseFiltersProps<Schema extends z.ZodTypeAny> = {
schema: Schema
defaultValues: DefaultValues<z.infer<Schema>>
}

export const useFilters = <Schema extends z.ZodTypeAny>({ schema, defaultValues }: UseFiltersProps<Schema>) => {
const { control, handleSubmit } = useForm<z.infer<Schema>>({
resolver: zodResolver(schema),
defaultValues,
})

const router = useRouter()
const values = useWatch({ control })

const update = (values: z.infer<Schema>) => {
const v = pickBy(values, (value) => value !== null)
router.push({ query: v }, undefined, { shallow: true })
}

return {
control,
values,
update: handleSubmit(update),
}
}
type UseFiltersProps<Schema extends z.ZodTypeAny> = {
schema: Schema
defaultValues: DefaultValues<z.infer<Schema>>
}

export const useFilters = <Schema extends z.ZodTypeAny>({ schema, defaultValues }: UseFiltersProps<Schema>) => {
const { control, handleSubmit } = useForm<z.infer<Schema>>({
resolver: zodResolver(schema),
defaultValues,
})

const router = useRouter()
const values = useWatch({ control })

const update = (values: z.infer<Schema>) => {
const v = pickBy(values, (value) => value !== null)
router.push({ query: v }, undefined, { shallow: true })
}

return {
control,
values,
update: handleSubmit(update),
}
}
4 replies
TTCTheo's Typesafe Cult
Created by samuele on 9/1/2023 in #questions
broken dinamic page react quey
4 replies
TTCTheo's Typesafe Cult
Created by samuele on 9/1/2023 in #questions
broken dinamic page react quey
Because it's not something you can do on client/component. Use router for that
4 replies
TTCTheo's Typesafe Cult
Created by chnmrn. on 6/28/2023 in #questions
ts-node not recognize
Yeah but it's unnecessary since ts-node works with nodemon without configuration
7 replies
TTCTheo's Typesafe Cult
Created by chnmrn. on 6/28/2023 in #questions
ts-node not recognize
nodemon will use ts-node
7 replies
TTCTheo's Typesafe Cult
Created by chnmrn. on 6/28/2023 in #questions
ts-node not recognize
Keep the nodemon part but remove ts-node stuff from the dev script
7 replies
TTCTheo's Typesafe Cult
Created by rocawear on 6/27/2023 in #questions
How to disable App Dir?
I did not get message after I removed experimental from next config
4 replies
TTCTheo's Typesafe Cult
Created by rocawear on 6/27/2023 in #questions
How to disable App Dir?
I also dont have app/ folder
4 replies
TTCTheo's Typesafe Cult
Created by niels on 6/27/2023 in #questions
useQuery endless fetching loop
What happens if you change to static queryKey
15 replies
TTCTheo's Typesafe Cult
Created by rocawear on 6/25/2023 in #questions
Prisma Schema
This sounds abit hacky because i would like to keep history of questions (i am storing answers so those would be gone after update):
const j = await db.feedback.update({
where: { id: params.feedbackId },
data: {
name: payload.name,
questions: {
deleteMany: {},
create: payload.questions,
},
},
include: { questions: true },
});
const j = await db.feedback.update({
where: { id: params.feedbackId },
data: {
name: payload.name,
questions: {
deleteMany: {},
create: payload.questions,
},
},
include: { questions: true },
});
6 replies
TTCTheo's Typesafe Cult
Created by rocawear on 6/25/2023 in #questions
Prisma Schema
That code updates feedback name as expected but not sure how to update questions so what i would want is to update the feedback to be what i send
6 replies
TTCTheo's Typesafe Cult
Created by rocawear on 6/25/2023 in #questions
Prisma Schema
Here not sure how to update it correctly, I using useArrayFields() on my frontend and I am sending data like:
{
"name": "feed",
"questions": [
{
"content": "jkjjj"
},
{
"content": "jkjjjdddd"
}
]
}
{
"name": "feed",
"questions": [
{
"content": "jkjjj"
},
{
"content": "jkjjjdddd"
}
]
}
const j = await db.feedback.update({
where: { id: params.feedbackId },
data: {
name: payload.name,
questions: {},
},
include: { questions: true },
});
const j = await db.feedback.update({
where: { id: params.feedbackId },
data: {
name: payload.name,
questions: {},
},
include: { questions: true },
});
6 replies
TTCTheo's Typesafe Cult
Created by rocawear on 6/25/2023 in #questions
Prisma Schema
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
organisations OrganisationsOnUsers[]
feedbacks Feedback[]
answers Answer[]
}

model Organisation {
id String @id @default(cuid())
name String
users OrganisationsOnUsers[]
feedbacks Feedback[]
answers Answer[]
}

model OrganisationsOnUsers {
user User @relation(fields: [userId], references: [id])
userId String
organisation Organisation @relation(fields: [organisationId], references: [id])
organisationId String
role String @default("user")

@@id([userId, organisationId])
}

model Feedback {
id String @id @default(cuid())
name String
organisation Organisation @relation(fields: [organisationId], references: [id])
organisationId String
questions Question[]
answers Answer[]
user User? @relation(fields: [userId], references: [id])
userId String?
}

model Question {
id String @id @default(cuid())
content String
feedback Feedback @relation(fields: [feedbackId], references: [id])
feedbackId String
answers Answer[]
}

model Answer {
id String @id @default(cuid())
value Int
question Question @relation(fields: [questionId], references: [id])
questionId String
user User @relation(fields: [userId], references: [id])
userId String
organisation Organisation @relation(fields: [organisationId], references: [id])
organisationId String
feedback Feedback? @relation(fields: [feedbackId], references: [id])
feedbackId String?

@@unique([userId, questionId])
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
organisations OrganisationsOnUsers[]
feedbacks Feedback[]
answers Answer[]
}

model Organisation {
id String @id @default(cuid())
name String
users OrganisationsOnUsers[]
feedbacks Feedback[]
answers Answer[]
}

model OrganisationsOnUsers {
user User @relation(fields: [userId], references: [id])
userId String
organisation Organisation @relation(fields: [organisationId], references: [id])
organisationId String
role String @default("user")

@@id([userId, organisationId])
}

model Feedback {
id String @id @default(cuid())
name String
organisation Organisation @relation(fields: [organisationId], references: [id])
organisationId String
questions Question[]
answers Answer[]
user User? @relation(fields: [userId], references: [id])
userId String?
}

model Question {
id String @id @default(cuid())
content String
feedback Feedback @relation(fields: [feedbackId], references: [id])
feedbackId String
answers Answer[]
}

model Answer {
id String @id @default(cuid())
value Int
question Question @relation(fields: [questionId], references: [id])
questionId String
user User @relation(fields: [userId], references: [id])
userId String
organisation Organisation @relation(fields: [organisationId], references: [id])
organisationId String
feedback Feedback? @relation(fields: [feedbackId], references: [id])
feedbackId String?

@@unique([userId, questionId])
}
6 replies
TTCTheo's Typesafe Cult
Created by rocawear on 6/21/2023 in #questions
TypeScript problem
https://tsplay.dev/mbaZ8N this kinda works but cant return array (i know i have type AnyZodObject but had alot of errors when using ZodAnyType) and if i hover my procedure it thinks there is input
{
method: "get",
path: "/todos/getAll",
output: z.object({
id: z.string(),
text: z.string(),
value: z.boolean(),
}),
procedure: () => {
return { id: "1", text: "wasd", value: false };
},
},
{
method: "get",
path: "/todos/getAll",
output: z.object({
id: z.string(),
text: z.string(),
value: z.boolean(),
}),
procedure: () => {
return { id: "1", text: "wasd", value: false };
},
},
3 replies
TTCTheo's Typesafe Cult
Created by rocawear on 6/21/2023 in #questions
TypeScript problem
Also every feedback and suggestion is really appreciated! This is still very alpha version but got stuck now
3 replies