mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-04 10:30:00 -06:00
move attributes to root level in local storage
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { attributeCache } from "@formbricks/lib/attribute/cache";
|
||||
import { getAttributesByUserId } from "@formbricks/lib/attribute/service";
|
||||
import { cache } from "@formbricks/lib/cache";
|
||||
import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants";
|
||||
import { displayCache } from "@formbricks/lib/display/cache";
|
||||
|
||||
@@ -42,7 +42,6 @@ export const updateAttribute = async (
|
||||
const res = await api.client.attribute.update({ userId, attributes: { [key]: value } });
|
||||
|
||||
if (!res.ok) {
|
||||
// @ts-expect-error
|
||||
if (res.error.details?.ignore) {
|
||||
logger.error(res.error.message ?? `Error updating person with userId ${userId}`);
|
||||
return {
|
||||
@@ -55,7 +54,6 @@ export const updateAttribute = async (
|
||||
}
|
||||
return err({
|
||||
code: "network_error",
|
||||
// @ts-expect-error
|
||||
status: res.error.status ?? 500,
|
||||
message: res.error.message ?? `Error updating person with userId ${userId}`,
|
||||
url: `${config.get().apiHost}/api/v1/client/${environmentId}/people/${userId}/attributes`,
|
||||
@@ -93,7 +91,7 @@ export const updateAttributes = async (
|
||||
const updatedAttributes = { ...attributes };
|
||||
|
||||
try {
|
||||
const existingAttributes = config.get().personState.data.attributes;
|
||||
const existingAttributes = config.get().attributes;
|
||||
if (existingAttributes) {
|
||||
for (const [key, value] of Object.entries(existingAttributes)) {
|
||||
if (updatedAttributes[key] === value) {
|
||||
@@ -123,7 +121,6 @@ export const updateAttributes = async (
|
||||
if (res.ok) {
|
||||
return ok(updatedAttributes);
|
||||
} else {
|
||||
// @ts-expect-error
|
||||
if (res.error.details?.ignore) {
|
||||
logger.error(res.error.message ?? `Error updating person with userId ${userId}`);
|
||||
return ok(updatedAttributes);
|
||||
@@ -140,7 +137,7 @@ export const updateAttributes = async (
|
||||
};
|
||||
|
||||
export const isExistingAttribute = (key: string, value: string): boolean => {
|
||||
if (config.get().personState.data.attributes[key] === value) {
|
||||
if (config.get().attributes[key] === value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -239,6 +239,7 @@ export const initialize = async (
|
||||
environmentState,
|
||||
personState,
|
||||
filteredSurveys,
|
||||
attributes: configInput.attributes || {},
|
||||
});
|
||||
|
||||
const surveyNames = filteredSurveys.map((s) => s.name);
|
||||
@@ -280,6 +281,7 @@ export const initialize = async (
|
||||
personState,
|
||||
environmentState,
|
||||
filteredSurveys,
|
||||
attributes: configInput.attributes || {},
|
||||
});
|
||||
} catch (e) {
|
||||
handleErrorOnFirstInit();
|
||||
@@ -293,15 +295,9 @@ export const initialize = async (
|
||||
if (updatedAttributes && Object.keys(updatedAttributes).length > 0) {
|
||||
config.update({
|
||||
...config.get(),
|
||||
personState: {
|
||||
...config.get().personState,
|
||||
data: {
|
||||
...config.get().personState.data,
|
||||
attributes: {
|
||||
...config.get().personState.data.attributes,
|
||||
...updatedAttributes,
|
||||
},
|
||||
},
|
||||
attributes: {
|
||||
...config.get().attributes,
|
||||
...updatedAttributes,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -145,6 +145,7 @@ export const ZJsConfig = z.object({
|
||||
environmentState: ZJsEnvironmentState,
|
||||
personState: ZJsPersonState,
|
||||
filteredSurveys: z.array(ZSurvey).default([]),
|
||||
attributes: z.record(z.string()),
|
||||
status: z.object({
|
||||
value: z.enum(["success", "error"]),
|
||||
expiresAt: z.date().nullable(),
|
||||
|
||||
Reference in New Issue
Block a user