Merge branch 'main' of github.com:formbricks/formbricks

This commit is contained in:
Johannes
2023-04-12 12:15:28 +02:00
6 changed files with 17 additions and 54 deletions
@@ -55,6 +55,7 @@ interface EnvironmentsNavbarProps {
export default function EnvironmentsNavbar({ environmentId, session }: EnvironmentsNavbarProps) { export default function EnvironmentsNavbar({ environmentId, session }: EnvironmentsNavbarProps) {
const router = useRouter(); const router = useRouter();
const [loading, setLoading] = useState(false);
const { environment, isErrorEnvironment, isLoadingEnvironment } = useEnvironment(environmentId); const { environment, isErrorEnvironment, isLoadingEnvironment } = useEnvironment(environmentId);
const pathname = usePathname(); const pathname = usePathname();
@@ -180,7 +181,7 @@ export default function EnvironmentsNavbar({ environmentId, session }: Environme
router.push(`/environments/${newEnvironmentId}/`); router.push(`/environments/${newEnvironmentId}/`);
}; };
if (isLoadingEnvironment) { if (isLoadingEnvironment || loading) {
return <LoadingSpinner />; return <LoadingSpinner />;
} }
@@ -328,12 +329,9 @@ export default function EnvironmentsNavbar({ environmentId, session }: Environme
<div className="flex items-center"> <div className="flex items-center">
<ArrowRightOnRectangleIcon className="mr-2 h-4 w-4" /> <ArrowRightOnRectangleIcon className="mr-2 h-4 w-4" />
<button <button
onClick={async () => { onClick={() => {
try { signOut();
await signOut(); setLoading(true);
} catch (error) {
console.error("Failed to sign out:", error);
}
}}> }}>
Logout Logout
</button> </button>
@@ -19,10 +19,10 @@ const AddEmailAlertModal: React.FC<AddEmailAlertModalProps> = ({ open, setOpen }
]; ];
const onTest = () => { const onTest = () => {
console.log("Test button clicked!"); throw Error("not implemented");
}; };
const onSave = () => { const onSave = () => {
console.log("Save button clicked!"); throw Error("not implemented");
}; };
return ( return (
@@ -33,7 +33,5 @@ export default function ApiKeyList({
const environmentTypeId = findEnvironmentByType(product?.environments, environmentType); const environmentTypeId = findEnvironmentByType(product?.environments, environmentType);
console.log(environmentTypeId);
return <EditApiKeys environmentTypeId={environmentTypeId} environmentType={environmentType} />; return <EditApiKeys environmentTypeId={environmentTypeId} environmentType={environmentType} />;
} }
@@ -80,7 +80,7 @@ export default function RecontactOptionsCard({
)}> )}>
<Collapsible.CollapsibleTrigger asChild className="h-full w-full cursor-pointer"> <Collapsible.CollapsibleTrigger asChild className="h-full w-full cursor-pointer">
<div className="inline-flex px-4 py-6"> <div className="inline-flex px-4 py-6">
<div className="flex items-center pr-5 pl-2"> <div className="flex items-center pl-2 pr-5">
<CheckCircleIcon className="h-8 w-8 text-green-400" /> <CheckCircleIcon className="h-8 w-8 text-green-400" />
</div> </div>
<div> <div>
@@ -173,7 +173,7 @@ export default function RecontactOptionsCard({
htmlFor="newDays" htmlFor="newDays"
className="flex w-full cursor-pointer items-center rounded-lg border bg-slate-50 p-4"> className="flex w-full cursor-pointer items-center rounded-lg border bg-slate-50 p-4">
<RadioGroupItem <RadioGroupItem
value={inputDays.toString()} value={inputDays === 0 ? "1" : inputDays.toString()} //Fixes that both radio buttons are checked when inputDays is 0
id="newDays" id="newDays"
className="aria-checked:border-brand-dark mx-5 disabled:border-slate-400 aria-checked:border-2" className="aria-checked:border-brand-dark mx-5 disabled:border-slate-400 aria-checked:border-2"
/> />
@@ -184,7 +184,7 @@ export default function RecontactOptionsCard({
type="number" type="number"
min="1" min="1"
id="inputDays" id="inputDays"
value={inputDays} value={inputDays === 0 ? 1 : inputDays}
onChange={handleRecontactDaysChange} onChange={handleRecontactDaysChange}
className="ml-2 mr-2 inline w-16 text-center text-sm" className="ml-2 mr-2 inline w-16 text-center text-sm"
/> />
@@ -192,7 +192,7 @@ export default function RecontactOptionsCard({
</p> </p>
<p className="mt-2 text-xs font-normal text-slate-600"> <p className="mt-2 text-xs font-normal text-slate-600">
Overwrites waiting period between surveys to {inputDays} day(s). Overwrites waiting period between surveys to {inputDays === 0 ? 1 : inputDays} day(s).
</p> </p>
</div> </div>
</label> </label>
@@ -94,7 +94,7 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
const events = [ const events = [
...displays.map((display) => ({ ...displays.map((display) => ({
name: "formbricks_display_created", name: "formbricks_survey_displayed",
timestamp: display.createdAt, timestamp: display.createdAt,
userId: display.person?.attributes?.find((attr) => attr.attributeClass.name === "userId")?.value, userId: display.person?.attributes?.find((attr) => attr.attributeClass.name === "userId")?.value,
})), })),
@@ -24,6 +24,8 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
// lastSyncedAt is the last time the environment was synced (iso string) // lastSyncedAt is the last time the environment was synced (iso string)
const { users }: { users: FormbricksUser[] } = req.body; const { users }: { users: FormbricksUser[] } = req.body;
console.log(users);
for (const user of users) { for (const user of users) {
// check if user with this userId as attribute already exists // check if user with this userId as attribute already exists
const existingUser = await prisma.person.findFirst({ const existingUser = await prisma.person.findFirst({
@@ -54,43 +56,7 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
}, },
}); });
if (!existingUser) { if (existingUser) {
const attributeType: "noCode" = "noCode";
// create user with this attributes (create or connect attribute with the same attributeClass name)
await prisma.person.create({
data: {
attributes: {
create: Object.keys(user.attributes).map((key) => ({
value: user.attributes[key],
attributeClass: {
connectOrCreate: {
where: {
name_environmentId: {
name: key,
environmentId,
},
},
create: {
name: key,
type: attributeType,
environment: {
connect: {
id: environmentId,
},
},
},
},
},
})),
},
environment: {
connect: {
id: environmentId,
},
},
},
});
} else {
// user already exists, loop through attributes and update or create them // user already exists, loop through attributes and update or create them
const attributeType: "noCode" = "noCode"; const attributeType: "noCode" = "noCode";
for (const key of Object.keys(user.attributes)) { for (const key of Object.keys(user.attributes)) {
@@ -107,7 +73,7 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
id: existingAttribute.id, id: existingAttribute.id,
}, },
data: { data: {
value: user.attributes[key], value: user.attributes[key].toString(),
}, },
}); });
} else { } else {
@@ -125,6 +91,7 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
}, },
create: { create: {
name: key, name: key,
description: "Created by Posthog Import",
type: attributeType, type: attributeType,
environment: { environment: {
connect: { connect: {