Skip to content

Commit cfae37b

Browse files
thesocialdevclaude
authored andcommitted
fix: restore state machine as source of truth for events
- DynamicReviewTaskForm now gets events from state machine (source of truth) - Use permissions as middleware to filter/check user capabilities - Permissions no longer override the state machine's event determination - Maintain proper separation of concerns: state machine defines what's possible, permissions define what's allowed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6d3ab83 commit cfae37b

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/components/ClaimReview/form/DynamicReviewTaskForm.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ const DynamicReviewTaskForm = ({ data_hash, personality, target, canInteract = t
6767
const [isLoggedIn] = useAtom(isUserLoggedIn);
6868
const [userId] = useAtom(currentUserId);
6969

70-
// Use centralized permission system
70+
// Use centralized permission system as middleware only
7171
const permissions = useReviewTaskPermissions();
7272

7373
const resetIsLoading = () => {
7474
const isLoading = {};
75-
permissions.canSubmitActions?.forEach((eventName) => {
75+
events?.forEach((eventName) => {
7676
isLoading[eventName] = false;
7777
});
7878
setIsLoading(isLoading);
@@ -88,7 +88,7 @@ const DynamicReviewTaskForm = ({ data_hash, personality, target, canInteract = t
8888
reset(reviewData);
8989
resetIsLoading();
9090
setReviewerError(false);
91-
}, [permissions.canSubmitActions]);
91+
}, [events]);
9292

9393
useAutoSaveDraft(data_hash, personality, target, watch);
9494

@@ -225,8 +225,16 @@ const DynamicReviewTaskForm = ({ data_hash, personality, target, canInteract = t
225225
else if (event === ReviewTaskEvents.draft) handleSendEvent(event);
226226
};
227227

228-
// Use centralized permission system for button visibility
229-
const showButtons = permissions.canSubmitActions.length > 0;
228+
// Check if user can perform any actions as middleware
229+
const canUserInteractWithForm = () => {
230+
// If no events from state machine, no buttons
231+
if (!events || events.length === 0) return false;
232+
233+
// Use permissions as middleware to check if user can perform any action
234+
return permissions.showForm && canInteract;
235+
};
236+
237+
const showButtons = canUserInteractWithForm();
230238

231239
return (
232240
<form style={{ width: "100%" }} onSubmit={handleSubmit(onSubmit)}>
@@ -249,7 +257,7 @@ const DynamicReviewTaskForm = ({ data_hash, personality, target, canInteract = t
249257
</Typography>
250258
)}
251259
</div>
252-
{permissions.canSubmitActions?.length > 0 && showButtons && (
260+
{events?.length > 0 && showButtons && (
253261
<AletheiaCaptcha
254262
onChange={setRecaptchaString}
255263
ref={recaptchaRef}
@@ -266,7 +274,13 @@ const DynamicReviewTaskForm = ({ data_hash, personality, target, canInteract = t
266274
gap: "10px",
267275
}}
268276
>
269-
{permissions.canSubmitActions?.map((event) => {
277+
{events?.map((event) => {
278+
// Use permissions as middleware to check if user can perform this specific action
279+
const canPerformAction = permissions.canSubmitActions.includes(event);
280+
281+
// Skip rendering button if user can't perform this action
282+
if (!canPerformAction) return null;
283+
270284
// Use standard label - confirmRejection event now has its own translation
271285
const eventLabel = t(`reviewTask:${event}`);
272286

0 commit comments

Comments
 (0)