Add snapshot of user attributes to a response (#403)

* feat: added current person attributes to the user response

* feat: added tooltip showing user attributes in response view

* fix: switched to using the service layer and added annotations for json field

* rename PersonAttributesData to ResponsePersonAttributes to fit current naming scheme

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
Pradumn Kumar
2023-06-21 16:32:55 +05:30
committed by GitHub
parent 08717cd396
commit 6922b3ed3f
9 changed files with 66 additions and 35 deletions
+2 -1
View File
@@ -1,5 +1,5 @@
import { TEventClassNoCodeConfig } from "@formbricks/types/v1/eventClasses";
import { TResponseData } from "@formbricks/types/v1/responses";
import { TResponsePersonAttributes, TResponseData } from "@formbricks/types/v1/responses";
import { TSurveyQuestions, TSurveyThankYouCard } from "@formbricks/types/v1/surveys";
import { TUserNotificationSettings } from "@formbricks/types/v1/users";
@@ -9,6 +9,7 @@ declare global {
export type EventClassNoCodeConfig = TEventClassNoCodeConfig;
export type ResponseData = TResponseData;
export type ResponseMeta = { [key: string]: string };
export type ResponsePersonAttributes = TResponsePersonAttributes;
export type SurveyQuestions = TSurveyQuestions;
export type SurveyThankYouCard = TSurveyThankYouCard;
export type UserNotificationSettings = TUserNotificationSettings;
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Response" ADD COLUMN "personAttributes" JSONB;
+15 -12
View File
@@ -87,21 +87,24 @@ model Person {
}
model Response {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
finished Boolean @default(false)
survey Survey @relation(fields: [surveyId], references: [id], onDelete: Cascade)
surveyId String
person Person? @relation(fields: [personId], references: [id], onDelete: Cascade)
personId String?
responseNotes ResponseNote[]
/// @zod.custom(imports.ZResponseData)
id String @id @default(cuid())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @updatedAt @map(name: "updated_at")
finished Boolean @default(false)
survey Survey @relation(fields: [surveyId], references: [id], onDelete: Cascade)
surveyId String
person Person? @relation(fields: [personId], references: [id], onDelete: Cascade)
personId String?
responseNotes ResponseNote[]
/// @zod.custom(imports.ZResponsePersonAttributes)
/// [ResponsePersonAttributes]
personAttributes Json?
/// @zod.custom(imports.ZResponseData)
/// [ResponseData]
data Json @default("{}")
data Json @default("{}")
/// @zod.custom(imports.ZResponseMeta)
/// [ResponseMeta]
meta Json @default("{}")
meta Json @default("{}")
}
model ResponseNote {
+1 -1
View File
@@ -3,7 +3,7 @@ import z from "zod";
export const ZEventProperties = z.record(z.string());
export { ZEventClassNoCodeConfig } from "@formbricks/types/v1/eventClasses";
export { ZResponseData } from "@formbricks/types/v1/responses";
export { ZResponseData, ZResponsePersonAttributes } from "@formbricks/types/v1/responses";
export const ZResponseMeta = z.record(z.union([z.string(), z.number()]));
export { ZSurveyQuestions, ZSurveyThankYouCard } from "@formbricks/types/v1/surveys";