@processmaker/screen-builder 3.8.24 → 3.8.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@processmaker/screen-builder",
3
- "version": "3.8.24",
3
+ "version": "3.8.26",
4
4
  "scripts": {
5
5
  "dev": "VITE_COVERAGE=true vite",
6
6
  "build": "vite build",
@@ -912,42 +912,53 @@ export default {
912
912
  * @param {Object} data - The event data containing the tokenId of the task.
913
913
  */
914
914
  async handleRedirectToTask(data) {
915
- if (
916
- (data?.params[0]?.tokenId &&
917
- this.task.user?.id === data.params[0]?.userId) ||
918
- this.task.elementDestination?.type === 'taskSource'
919
- ) {
920
- this.loadingTask = true;
921
- // Check if interstitial tasks are allowed for this task.
922
- if (this.task && !(this.task.allow_interstitial || this.isSameUser(this.task, data))) {
923
- // The getDestinationUrl() function is called asynchronously to retrieve the URL
924
- window.location.href = await this.getDestinationUrl();
925
- return;
926
- }
927
- this.nodeId = data.params[0].nodeId;
928
- this.taskId = data.params[0].tokenId;
929
-
930
- // Force a redirect to ensure the correct task is loaded immediately for ConversationalForm.
931
- // This prevents async reloads that may cause inconsistencies specific to ConversationalForm.
932
- if (this.renderComponent === "ConversationalForm") {
933
- window.location.href = `/tasks/${this.taskId}/edit`;
915
+ const tokenId = data?.params[0]?.tokenId;
916
+ const newTaskUserId = data?.params[0]?.userId; // User assigned to the new task (from the backend)
917
+ const nodeId = data?.params[0]?.nodeId;
918
+ // Current user: prop > window.ProcessMaker.user > task assignee (when viewing assigned task)
919
+ const currentUserId = this.userId ?? window.ProcessMaker?.user?.id ?? this.task?.user?.id;
920
+ const elementDestType = this.task?.elementDestination?.type;
921
+ const userCanClaim = data?.params?.[0]?.userCanClaim;
922
+ // Redirect if the new task is assigned to the current user, or if it is taskSource
923
+ const isNewTaskForCurrentUser = tokenId && (newTaskUserId === currentUserId || (newTaskUserId == null && (elementDestType === 'displayNextAssignedTask' || elementDestType === 'taskSource')));
924
+ const isTaskSource = elementDestType === 'taskSource';
925
+ // Redirect when task is unclaimed and user can claim it (pool tasks)
926
+ const isUnclaimedAndClaimable = newTaskUserId === null && userCanClaim === true;
927
+ const shouldHandle = isNewTaskForCurrentUser || isTaskSource || isUnclaimedAndClaimable;
928
+
929
+ if (shouldHandle) {
930
+ this.loadingTask = true;
931
+ // Check if interstitial tasks are allowed for this task.
932
+ if (this.task && !(this.task.allow_interstitial || this.isSameUser(data))) {
933
+ window.location.href = await this.getDestinationUrl();
934
+ return;
935
+ }
936
+ this.nodeId = nodeId;
937
+ this.taskId = tokenId;
938
+
939
+ // Force a redirect to ensure the correct task is loaded immediately for ConversationalForm.
940
+ if (this.renderComponent === "ConversationalForm") {
941
+ window.location.href = `/tasks/${this.taskId}/edit`;
942
+ }
943
+
944
+ this.reload();
934
945
  }
935
-
936
- this.reload();
937
- }
938
946
  },
939
947
 
940
948
  /**
941
- * Checks if the current task and the redirect data belong to the same user.
942
- * and the destination is taskSource.
949
+ * Checks if the redirect applies to the current user.
950
+ * - userId of event = user assigned to the new task
951
+ * - It is considered a match if: new task assigned to the current user, or taskSource/displayNextAssignedTask with user null
943
952
  *
944
- * @param {Object} currentTask - The current task object.
945
953
  * @param {Object} redirectData - The redirect data object.
946
954
  */
947
- isSameUser(currentTask, redirectData) {
948
- const userIdMatch = currentTask.user?.id === redirectData.params[0].userId;
949
- const typeMatch = currentTask.elementDestination?.type === null
950
- || currentTask.elementDestination?.type === 'taskSource';
955
+ isSameUser(redirectData) {
956
+ const newTaskUserId = redirectData?.params?.[0]?.userId;
957
+ const currentUserId = this.userId ?? window.ProcessMaker?.user?.id ?? this.task?.user?.id;
958
+ const elementDestType = this.task?.elementDestination?.type;
959
+ const userIdMatch = newTaskUserId === currentUserId
960
+ || (newTaskUserId == null && (elementDestType === 'displayNextAssignedTask' || elementDestType === 'taskSource'));
961
+ const typeMatch = elementDestType === null || elementDestType === 'taskSource' || elementDestType === 'displayNextAssignedTask';
951
962
 
952
963
  return userIdMatch && typeMatch;
953
964
  },