Skip to content

Commit 9e568d8

Browse files
committed
fix: removing revalidate post message
1 parent 8f2da6e commit 9e568d8

5 files changed

Lines changed: 250 additions & 389 deletions

File tree

src/visualBuilder/components/fieldLabelWrapper.tsx

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ContentTypeIcon } from "./icons";
1818
import { ToolbarTooltip } from "./Tooltip";
1919
import { fetchEntryPermissionsAndStageDetails } from "../utils/fetchEntryPermissionsAndStageDetails";
2020
import { VariantIndicator } from "./VariantIndicator";
21+
import { handleRevalidateFieldData } from "../eventManager/useRevalidateFieldDataPostMessageEvent";
2122

2223
interface ReferenceParentMap {
2324
[entryUid: string]: {
@@ -171,16 +172,37 @@ function FieldLabelWrapperComponent(
171172
entryWorkflowStageDetails
172173
);
173174

174-
const handleLinkVariant = () => {
175+
const handleLinkVariant = async () => {
175176
if (fieldSchema.field_metadata?.canLinkVariant) {
176-
visualBuilderPostMessage?.send(
177-
VisualBuilderPostMessageEvents.OPEN_LINK_VARIANT_MODAL,
178-
{
179-
contentTypeUid:
180-
props.fieldMetadata
181-
.content_type_uid,
177+
try {
178+
const result = await visualBuilderPostMessage?.send<{
179+
success?: boolean;
180+
action?: string;
181+
message?: string;
182+
error?: boolean;
183+
}>(
184+
VisualBuilderPostMessageEvents.OPEN_LINK_VARIANT_MODAL,
185+
{
186+
contentTypeUid:
187+
props.fieldMetadata.content_type_uid,
188+
}
189+
);
190+
191+
// If the modal was closed or linking failed, do nothing
192+
if (!result || !result.success) {
193+
return;
194+
}
195+
196+
// If linking was successful and requires revalidation, revalidate
197+
if (result.action === "revalidate") {
198+
await handleRevalidateFieldData();
182199
}
183-
);
200+
} catch (error) {
201+
console.error(
202+
"Error in link variant modal flow:",
203+
error
204+
);
205+
}
184206
}
185207
};
186208

@@ -202,13 +224,13 @@ function FieldLabelWrapperComponent(
202224
]
203225
)}
204226
data-tooltip={!reason?.toLowerCase().includes("click here to link a variant")
205-
? reason
227+
? reason
206228
: undefined}
207229
>
208230
{reason
209231
.toLowerCase()
210232
.includes("click here to link a variant") && (
211-
<div
233+
<div
212234
className={visualBuilderStyles()["visual-builder__custom-tooltip"]}
213235
onClick={handleLinkVariant}
214236
>

0 commit comments

Comments
 (0)