@smvtech/x-flux 1.0.6 → 1.0.8

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/dist/index.d.mts CHANGED
@@ -5271,6 +5271,7 @@ type TEDCFlowContext = {
5271
5271
  updateAnswer: (application_id: string, question_type: QUESTION_TYPE, question: string, data: TUpdateAnswerPayload, onProgress?: (event: TUploadProgressEvent) => void) => Promise<void>;
5272
5272
  getS3UrlForAsset: (doc_id: string) => Promise<string | null>;
5273
5273
  acceptOrderQCTermsAndConditions: () => Promise<void>;
5274
+ runAllValidations: () => Promise<void>;
5274
5275
  };
5275
5276
  type TEDCFlowProviderProps = {
5276
5277
  children: ReactNode;
@@ -5280,12 +5281,12 @@ declare const EDCFlowProvider: react__default.FC<TEDCFlowProviderProps>;
5280
5281
  declare const useEDCFlow: () => TEDCFlowContext;
5281
5282
 
5282
5283
  declare const createAllQuestionsWithAnswers: (questionnaire: TQuestionnaire, answers?: TAnswer[]) => TQuestionWithAnswer[];
5283
- declare const filterConditionalQuestions: (questions: TQuestionWithAnswer[], order: TVisaOrder) => TQuestionWithAnswer[];
5284
- declare const getVisibleQuestions: (questions: TQuestionWithAnswer[], order: TVisaOrder) => TQuestionWithAnswer[];
5284
+ declare const filterConditionalQuestions: (questions: TQuestionWithAnswer[], application: TApplication) => TQuestionWithAnswer[];
5285
+ declare const getVisibleQuestions: (questions: TQuestionWithAnswer[], application: TApplication) => TQuestionWithAnswer[];
5285
5286
  declare const formatTravellerFromResponse: (traveller: TTraveller) => TTraveller;
5286
5287
  declare const formatAnswerFromResponse: (updatedAnswer: TAnswer, orderId: string) => TAnswer;
5287
- declare const updateApplicantWithAnswer: (applicant: TEDCApplicant, question_id: string, answer: TAnswer, questionnaire: TQuestionnaire, order: TVisaOrder) => TEDCApplicant;
5288
- declare const createApplicantData: (traveller: TTraveller, answers: TAnswer[], questionnaire: TQuestionnaire, application: TApplication, order: TVisaOrder) => TEDCApplicant | null;
5288
+ declare const updateApplicantWithAnswer: (applicant: TEDCApplicant, question_id: string, answer: TAnswer, questionnaire: TQuestionnaire) => TEDCApplicant;
5289
+ declare const createApplicantData: (traveller: TTraveller, answers: TAnswer[], questionnaire: TQuestionnaire, application: TApplication) => TEDCApplicant | null;
5289
5290
  declare function getSignedUrlFromAsset(docId: string): Promise<string | null>;
5290
5291
 
5291
5292
  declare const initializeEDCFlow: (config: EDCConfig) => void;
@@ -5312,6 +5313,7 @@ declare const EDCFlow: {
5312
5313
  updateAnswer: (application_id: string, question_type: QUESTION_TYPE, question: string, data: TUpdateAnswerPayload, onProgress?: (event: TUploadProgressEvent) => void) => Promise<void>;
5313
5314
  getS3UrlForAsset: (doc_id: string) => Promise<string | null>;
5314
5315
  acceptOrderQCTermsAndConditions: () => Promise<void>;
5316
+ runAllValidations: () => Promise<void>;
5315
5317
  };
5316
5318
  };
5317
5319
 
package/dist/index.d.ts CHANGED
@@ -5271,6 +5271,7 @@ type TEDCFlowContext = {
5271
5271
  updateAnswer: (application_id: string, question_type: QUESTION_TYPE, question: string, data: TUpdateAnswerPayload, onProgress?: (event: TUploadProgressEvent) => void) => Promise<void>;
5272
5272
  getS3UrlForAsset: (doc_id: string) => Promise<string | null>;
5273
5273
  acceptOrderQCTermsAndConditions: () => Promise<void>;
5274
+ runAllValidations: () => Promise<void>;
5274
5275
  };
5275
5276
  type TEDCFlowProviderProps = {
5276
5277
  children: ReactNode;
@@ -5280,12 +5281,12 @@ declare const EDCFlowProvider: react__default.FC<TEDCFlowProviderProps>;
5280
5281
  declare const useEDCFlow: () => TEDCFlowContext;
5281
5282
 
5282
5283
  declare const createAllQuestionsWithAnswers: (questionnaire: TQuestionnaire, answers?: TAnswer[]) => TQuestionWithAnswer[];
5283
- declare const filterConditionalQuestions: (questions: TQuestionWithAnswer[], order: TVisaOrder) => TQuestionWithAnswer[];
5284
- declare const getVisibleQuestions: (questions: TQuestionWithAnswer[], order: TVisaOrder) => TQuestionWithAnswer[];
5284
+ declare const filterConditionalQuestions: (questions: TQuestionWithAnswer[], application: TApplication) => TQuestionWithAnswer[];
5285
+ declare const getVisibleQuestions: (questions: TQuestionWithAnswer[], application: TApplication) => TQuestionWithAnswer[];
5285
5286
  declare const formatTravellerFromResponse: (traveller: TTraveller) => TTraveller;
5286
5287
  declare const formatAnswerFromResponse: (updatedAnswer: TAnswer, orderId: string) => TAnswer;
5287
- declare const updateApplicantWithAnswer: (applicant: TEDCApplicant, question_id: string, answer: TAnswer, questionnaire: TQuestionnaire, order: TVisaOrder) => TEDCApplicant;
5288
- declare const createApplicantData: (traveller: TTraveller, answers: TAnswer[], questionnaire: TQuestionnaire, application: TApplication, order: TVisaOrder) => TEDCApplicant | null;
5288
+ declare const updateApplicantWithAnswer: (applicant: TEDCApplicant, question_id: string, answer: TAnswer, questionnaire: TQuestionnaire) => TEDCApplicant;
5289
+ declare const createApplicantData: (traveller: TTraveller, answers: TAnswer[], questionnaire: TQuestionnaire, application: TApplication) => TEDCApplicant | null;
5289
5290
  declare function getSignedUrlFromAsset(docId: string): Promise<string | null>;
5290
5291
 
5291
5292
  declare const initializeEDCFlow: (config: EDCConfig) => void;
@@ -5312,6 +5313,7 @@ declare const EDCFlow: {
5312
5313
  updateAnswer: (application_id: string, question_type: QUESTION_TYPE, question: string, data: TUpdateAnswerPayload, onProgress?: (event: TUploadProgressEvent) => void) => Promise<void>;
5313
5314
  getS3UrlForAsset: (doc_id: string) => Promise<string | null>;
5314
5315
  acceptOrderQCTermsAndConditions: () => Promise<void>;
5316
+ runAllValidations: () => Promise<void>;
5315
5317
  };
5316
5318
  };
5317
5319
 
package/dist/index.js CHANGED
@@ -234,7 +234,7 @@ var createAllQuestionsWithAnswers = (questionnaire, answers = []) => {
234
234
  });
235
235
  return questionsWithAnswers;
236
236
  };
237
- var filterConditionalQuestions = (questions, order) => {
237
+ var filterConditionalQuestions = (questions, application) => {
238
238
  const questionMap = /* @__PURE__ */ new Map();
239
239
  questions.forEach((q) => {
240
240
  questionMap.set(q.id, q);
@@ -245,7 +245,7 @@ var filterConditionalQuestions = (questions, order) => {
245
245
  if (!question) return;
246
246
  const answerValue = question.answer_data?.answer || [];
247
247
  question.question.renders?.forEach((render) => {
248
- if (shouldRenderQuestion(render, answerValue, order)) {
248
+ if (shouldRenderQuestion(render, answerValue, application)) {
249
249
  render.question_ids.forEach((id) => {
250
250
  if (!visibleQuestionIds.has(id)) {
251
251
  visibleQuestionIds.add(id);
@@ -267,29 +267,21 @@ var extractDynamicFieldName = (value) => {
267
267
  const match = value.match(/^\{\{([^}]+)\}\}$/);
268
268
  return match ? match[1].trim() : null;
269
269
  };
270
- var isMinor = (dateOfBirth, travelStartDate) => {
271
- if (!dateOfBirth || !travelStartDate) return false;
272
- let dob;
273
- if (dateOfBirth.includes("/")) {
274
- const [day, month, year] = dateOfBirth.split("/").map(Number);
275
- dob = new Date(year, month - 1, day);
276
- } else {
277
- dob = new Date(dateOfBirth);
278
- }
279
- const travelDate = new Date(travelStartDate);
280
- if (isNaN(dob.getTime()) || isNaN(travelDate.getTime())) return false;
281
- const ageDiff = travelDate.getFullYear() - dob.getFullYear();
282
- const monthDiff = travelDate.getMonth() - dob.getMonth();
283
- const dayDiff = travelDate.getDate() - dob.getDate();
284
- const actualAge = monthDiff < 0 || monthDiff === 0 && dayDiff < 0 ? ageDiff - 1 : ageDiff;
285
- return actualAge < 18;
286
- };
287
- var shouldRenderQuestion = (render, answerValue, order) => {
270
+ var shouldRenderQuestion = (render, answerValue, application) => {
288
271
  const dynamicFieldName = extractDynamicFieldName(render.value);
289
272
  if (dynamicFieldName) {
290
273
  switch (dynamicFieldName) {
291
- case "travel_start_date":
292
- return isMinor(answerValue[0], order.travel_start_date);
274
+ case "minor": {
275
+ const hasMinorTag = application.tags?.includes("MINOR" /* MINOR */) ?? false;
276
+ switch (render.operation) {
277
+ case "eq":
278
+ return hasMinorTag;
279
+ case "neq":
280
+ return !hasMinorTag;
281
+ default:
282
+ return false;
283
+ }
284
+ }
293
285
  default:
294
286
  return false;
295
287
  }
@@ -317,8 +309,8 @@ var shouldRenderQuestion = (render, answerValue, order) => {
317
309
  return false;
318
310
  }
319
311
  };
320
- var getVisibleQuestions = (questions, order) => {
321
- return filterConditionalQuestions(questions, order);
312
+ var getVisibleQuestions = (questions, application) => {
313
+ return filterConditionalQuestions(questions, application);
322
314
  };
323
315
  var formatApplicationFromResponse = (application) => {
324
316
  return {
@@ -366,7 +358,7 @@ var formatAnswerFromResponse = (updatedAnswer, orderId) => {
366
358
  updated_at: updatedAnswer.updated_at
367
359
  };
368
360
  };
369
- var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire, order) => {
361
+ var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire) => {
370
362
  const answerMap = /* @__PURE__ */ new Map();
371
363
  applicant.questions.forEach((q) => {
372
364
  if (q.answer_data) {
@@ -376,16 +368,16 @@ var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire,
376
368
  answerMap.set(question_id, answer);
377
369
  const answers = Array.from(answerMap.values());
378
370
  const questions = createAllQuestionsWithAnswers(questionnaire, answers);
379
- const visibleQuestions = getVisibleQuestions(questions, order);
371
+ const visibleQuestions = getVisibleQuestions(questions, applicant.application);
380
372
  return {
381
373
  ...applicant,
382
374
  questions: visibleQuestions
383
375
  };
384
376
  };
385
- var createApplicantData = (traveller, answers, questionnaire, application, order) => {
377
+ var createApplicantData = (traveller, answers, questionnaire, application) => {
386
378
  if (!questionnaire) return null;
387
379
  const questions = createAllQuestionsWithAnswers(questionnaire, answers);
388
- const visibleQuestions = getVisibleQuestions(questions, order);
380
+ const visibleQuestions = getVisibleQuestions(questions, application);
389
381
  return {
390
382
  application_id: application._id,
391
383
  application,
@@ -400,7 +392,7 @@ var transformApplicationResponse = (response) => {
400
392
  answers: (response.answers || []).map((answer) => formatAnswerFromResponse(answer, response.application.visa_order_id))
401
393
  };
402
394
  };
403
- var createApplicantsFromApplications = (applications, questionnaire, order) => {
395
+ var createApplicantsFromApplications = (applications, questionnaire) => {
404
396
  if (!applications || !Array.isArray(applications)) {
405
397
  return {};
406
398
  }
@@ -410,8 +402,7 @@ var createApplicantsFromApplications = (applications, questionnaire, order) => {
410
402
  applicationData.traveller,
411
403
  applicationData.answers,
412
404
  questionnaire,
413
- applicationData.application,
414
- order
405
+ applicationData.application
415
406
  );
416
407
  if (applicant) {
417
408
  applicants[applicationData.application._id] = applicant;
@@ -620,6 +611,11 @@ var getFileURLfromFilename = async (filename, signal) => {
620
611
  });
621
612
  return { data: signedURLs };
622
613
  };
614
+ var runAllValidations = async (orderId) => {
615
+ const client = getClient();
616
+ const response = await client.post(`/visa_orders/run-all-validations`, { order_id: orderId });
617
+ return { data: response.data.data };
618
+ };
623
619
  var updateOrderQCTermsAndConditions = async (orderId) => {
624
620
  const client = getClient();
625
621
  const response = await client.patch(`/visa_orders/update-order-qc-terms-conditions/${orderId}`);
@@ -688,8 +684,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
688
684
  newApplicant.traveller,
689
685
  newApplicant.answers,
690
686
  questionnaire,
691
- newApplicant.application,
692
- order
687
+ newApplicant.application
693
688
  );
694
689
  if (!applicant) {
695
690
  setError("Failed to create applicant data");
@@ -723,8 +718,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
723
718
  refreshedApplicantData.traveller,
724
719
  refreshedApplicantData.answers,
725
720
  questionnaire,
726
- refreshedApplicantData.application,
727
- order
721
+ refreshedApplicantData.application
728
722
  );
729
723
  if (!applicant) return;
730
724
  setApplicants((prev) => {
@@ -769,8 +763,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
769
763
  currentApplicant,
770
764
  updatedAnswerData.answers.visa_questions_id,
771
765
  updatedAnswerData.answers,
772
- questionnaire,
773
- order
766
+ questionnaire
774
767
  );
775
768
  const updatedApplicants = {
776
769
  ...prev,
@@ -861,6 +854,37 @@ var EDCFlowProvider = ({ children, orderId }) => {
861
854
  setError("Failed to accept order QCTerms and Conditions");
862
855
  }
863
856
  }, [order]);
857
+ const runAllValidationsHandler = react.useCallback(async () => {
858
+ if (!orderId || !questionnaire) return;
859
+ try {
860
+ setError(null);
861
+ const { data } = await runAllValidations(orderId);
862
+ if (data.order) {
863
+ setOrder(data.order);
864
+ }
865
+ if (data.applications && data.applications.length > 0) {
866
+ const applicants2 = createApplicantsFromApplications(
867
+ data.applications,
868
+ questionnaire
869
+ );
870
+ const { updatedQuestionnaire, updatedApplicants } = runApplicantSideEffects(applicants2, questionnaire, dynamicQuestionMap);
871
+ setQuestionnaire(updatedQuestionnaire);
872
+ setApplicants(updatedApplicants);
873
+ const applicantIds = Object.keys(updatedApplicants);
874
+ if (applicantIds.length > 0) {
875
+ if (activeApplicant && applicantIds.includes(activeApplicant)) {
876
+ setActiveApplicant(activeApplicant);
877
+ } else {
878
+ setActiveApplicant(applicantIds[0]);
879
+ }
880
+ }
881
+ }
882
+ setSuccess("Validations completed successfully");
883
+ } catch (err) {
884
+ console.error("Failed to run all validations:", err);
885
+ setError("Failed to run all validations");
886
+ }
887
+ }, [orderId, questionnaire, dynamicQuestionMap, activeApplicant]);
864
888
  react.useEffect(() => {
865
889
  if (!orderId) return;
866
890
  const initialize = async () => {
@@ -875,8 +899,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
875
899
  if (orderData && questionnaireData && applications) {
876
900
  const applicants2 = createApplicantsFromApplications(
877
901
  applications,
878
- questionnaireData,
879
- orderData
902
+ questionnaireData
880
903
  );
881
904
  const dynamicMap = buildDynamicQuestionMap(questionnaireData);
882
905
  const { updatedQuestionnaire, updatedApplicants } = runApplicantSideEffects(applicants2, questionnaireData, dynamicMap);
@@ -912,7 +935,8 @@ var EDCFlowProvider = ({ children, orderId }) => {
912
935
  refreshOrder,
913
936
  refreshApplicant,
914
937
  getS3UrlForAsset,
915
- acceptOrderQCTermsAndConditions
938
+ acceptOrderQCTermsAndConditions,
939
+ runAllValidations: runAllValidationsHandler
916
940
  };
917
941
  return /* @__PURE__ */ jsxRuntime.jsx(EDCFlowContext.Provider, { value, children });
918
942
  };
package/dist/index.mjs CHANGED
@@ -208,7 +208,7 @@ var createAllQuestionsWithAnswers = (questionnaire, answers = []) => {
208
208
  });
209
209
  return questionsWithAnswers;
210
210
  };
211
- var filterConditionalQuestions = (questions, order) => {
211
+ var filterConditionalQuestions = (questions, application) => {
212
212
  const questionMap = /* @__PURE__ */ new Map();
213
213
  questions.forEach((q) => {
214
214
  questionMap.set(q.id, q);
@@ -219,7 +219,7 @@ var filterConditionalQuestions = (questions, order) => {
219
219
  if (!question) return;
220
220
  const answerValue = question.answer_data?.answer || [];
221
221
  question.question.renders?.forEach((render) => {
222
- if (shouldRenderQuestion(render, answerValue, order)) {
222
+ if (shouldRenderQuestion(render, answerValue, application)) {
223
223
  render.question_ids.forEach((id) => {
224
224
  if (!visibleQuestionIds.has(id)) {
225
225
  visibleQuestionIds.add(id);
@@ -241,29 +241,21 @@ var extractDynamicFieldName = (value) => {
241
241
  const match = value.match(/^\{\{([^}]+)\}\}$/);
242
242
  return match ? match[1].trim() : null;
243
243
  };
244
- var isMinor = (dateOfBirth, travelStartDate) => {
245
- if (!dateOfBirth || !travelStartDate) return false;
246
- let dob;
247
- if (dateOfBirth.includes("/")) {
248
- const [day, month, year] = dateOfBirth.split("/").map(Number);
249
- dob = new Date(year, month - 1, day);
250
- } else {
251
- dob = new Date(dateOfBirth);
252
- }
253
- const travelDate = new Date(travelStartDate);
254
- if (isNaN(dob.getTime()) || isNaN(travelDate.getTime())) return false;
255
- const ageDiff = travelDate.getFullYear() - dob.getFullYear();
256
- const monthDiff = travelDate.getMonth() - dob.getMonth();
257
- const dayDiff = travelDate.getDate() - dob.getDate();
258
- const actualAge = monthDiff < 0 || monthDiff === 0 && dayDiff < 0 ? ageDiff - 1 : ageDiff;
259
- return actualAge < 18;
260
- };
261
- var shouldRenderQuestion = (render, answerValue, order) => {
244
+ var shouldRenderQuestion = (render, answerValue, application) => {
262
245
  const dynamicFieldName = extractDynamicFieldName(render.value);
263
246
  if (dynamicFieldName) {
264
247
  switch (dynamicFieldName) {
265
- case "travel_start_date":
266
- return isMinor(answerValue[0], order.travel_start_date);
248
+ case "minor": {
249
+ const hasMinorTag = application.tags?.includes("MINOR" /* MINOR */) ?? false;
250
+ switch (render.operation) {
251
+ case "eq":
252
+ return hasMinorTag;
253
+ case "neq":
254
+ return !hasMinorTag;
255
+ default:
256
+ return false;
257
+ }
258
+ }
267
259
  default:
268
260
  return false;
269
261
  }
@@ -291,8 +283,8 @@ var shouldRenderQuestion = (render, answerValue, order) => {
291
283
  return false;
292
284
  }
293
285
  };
294
- var getVisibleQuestions = (questions, order) => {
295
- return filterConditionalQuestions(questions, order);
286
+ var getVisibleQuestions = (questions, application) => {
287
+ return filterConditionalQuestions(questions, application);
296
288
  };
297
289
  var formatApplicationFromResponse = (application) => {
298
290
  return {
@@ -340,7 +332,7 @@ var formatAnswerFromResponse = (updatedAnswer, orderId) => {
340
332
  updated_at: updatedAnswer.updated_at
341
333
  };
342
334
  };
343
- var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire, order) => {
335
+ var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire) => {
344
336
  const answerMap = /* @__PURE__ */ new Map();
345
337
  applicant.questions.forEach((q) => {
346
338
  if (q.answer_data) {
@@ -350,16 +342,16 @@ var updateApplicantWithAnswer = (applicant, question_id, answer, questionnaire,
350
342
  answerMap.set(question_id, answer);
351
343
  const answers = Array.from(answerMap.values());
352
344
  const questions = createAllQuestionsWithAnswers(questionnaire, answers);
353
- const visibleQuestions = getVisibleQuestions(questions, order);
345
+ const visibleQuestions = getVisibleQuestions(questions, applicant.application);
354
346
  return {
355
347
  ...applicant,
356
348
  questions: visibleQuestions
357
349
  };
358
350
  };
359
- var createApplicantData = (traveller, answers, questionnaire, application, order) => {
351
+ var createApplicantData = (traveller, answers, questionnaire, application) => {
360
352
  if (!questionnaire) return null;
361
353
  const questions = createAllQuestionsWithAnswers(questionnaire, answers);
362
- const visibleQuestions = getVisibleQuestions(questions, order);
354
+ const visibleQuestions = getVisibleQuestions(questions, application);
363
355
  return {
364
356
  application_id: application._id,
365
357
  application,
@@ -374,7 +366,7 @@ var transformApplicationResponse = (response) => {
374
366
  answers: (response.answers || []).map((answer) => formatAnswerFromResponse(answer, response.application.visa_order_id))
375
367
  };
376
368
  };
377
- var createApplicantsFromApplications = (applications, questionnaire, order) => {
369
+ var createApplicantsFromApplications = (applications, questionnaire) => {
378
370
  if (!applications || !Array.isArray(applications)) {
379
371
  return {};
380
372
  }
@@ -384,8 +376,7 @@ var createApplicantsFromApplications = (applications, questionnaire, order) => {
384
376
  applicationData.traveller,
385
377
  applicationData.answers,
386
378
  questionnaire,
387
- applicationData.application,
388
- order
379
+ applicationData.application
389
380
  );
390
381
  if (applicant) {
391
382
  applicants[applicationData.application._id] = applicant;
@@ -594,6 +585,11 @@ var getFileURLfromFilename = async (filename, signal) => {
594
585
  });
595
586
  return { data: signedURLs };
596
587
  };
588
+ var runAllValidations = async (orderId) => {
589
+ const client = getClient();
590
+ const response = await client.post(`/visa_orders/run-all-validations`, { order_id: orderId });
591
+ return { data: response.data.data };
592
+ };
597
593
  var updateOrderQCTermsAndConditions = async (orderId) => {
598
594
  const client = getClient();
599
595
  const response = await client.patch(`/visa_orders/update-order-qc-terms-conditions/${orderId}`);
@@ -662,8 +658,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
662
658
  newApplicant.traveller,
663
659
  newApplicant.answers,
664
660
  questionnaire,
665
- newApplicant.application,
666
- order
661
+ newApplicant.application
667
662
  );
668
663
  if (!applicant) {
669
664
  setError("Failed to create applicant data");
@@ -697,8 +692,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
697
692
  refreshedApplicantData.traveller,
698
693
  refreshedApplicantData.answers,
699
694
  questionnaire,
700
- refreshedApplicantData.application,
701
- order
695
+ refreshedApplicantData.application
702
696
  );
703
697
  if (!applicant) return;
704
698
  setApplicants((prev) => {
@@ -743,8 +737,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
743
737
  currentApplicant,
744
738
  updatedAnswerData.answers.visa_questions_id,
745
739
  updatedAnswerData.answers,
746
- questionnaire,
747
- order
740
+ questionnaire
748
741
  );
749
742
  const updatedApplicants = {
750
743
  ...prev,
@@ -835,6 +828,37 @@ var EDCFlowProvider = ({ children, orderId }) => {
835
828
  setError("Failed to accept order QCTerms and Conditions");
836
829
  }
837
830
  }, [order]);
831
+ const runAllValidationsHandler = useCallback(async () => {
832
+ if (!orderId || !questionnaire) return;
833
+ try {
834
+ setError(null);
835
+ const { data } = await runAllValidations(orderId);
836
+ if (data.order) {
837
+ setOrder(data.order);
838
+ }
839
+ if (data.applications && data.applications.length > 0) {
840
+ const applicants2 = createApplicantsFromApplications(
841
+ data.applications,
842
+ questionnaire
843
+ );
844
+ const { updatedQuestionnaire, updatedApplicants } = runApplicantSideEffects(applicants2, questionnaire, dynamicQuestionMap);
845
+ setQuestionnaire(updatedQuestionnaire);
846
+ setApplicants(updatedApplicants);
847
+ const applicantIds = Object.keys(updatedApplicants);
848
+ if (applicantIds.length > 0) {
849
+ if (activeApplicant && applicantIds.includes(activeApplicant)) {
850
+ setActiveApplicant(activeApplicant);
851
+ } else {
852
+ setActiveApplicant(applicantIds[0]);
853
+ }
854
+ }
855
+ }
856
+ setSuccess("Validations completed successfully");
857
+ } catch (err) {
858
+ console.error("Failed to run all validations:", err);
859
+ setError("Failed to run all validations");
860
+ }
861
+ }, [orderId, questionnaire, dynamicQuestionMap, activeApplicant]);
838
862
  useEffect(() => {
839
863
  if (!orderId) return;
840
864
  const initialize = async () => {
@@ -849,8 +873,7 @@ var EDCFlowProvider = ({ children, orderId }) => {
849
873
  if (orderData && questionnaireData && applications) {
850
874
  const applicants2 = createApplicantsFromApplications(
851
875
  applications,
852
- questionnaireData,
853
- orderData
876
+ questionnaireData
854
877
  );
855
878
  const dynamicMap = buildDynamicQuestionMap(questionnaireData);
856
879
  const { updatedQuestionnaire, updatedApplicants } = runApplicantSideEffects(applicants2, questionnaireData, dynamicMap);
@@ -886,7 +909,8 @@ var EDCFlowProvider = ({ children, orderId }) => {
886
909
  refreshOrder,
887
910
  refreshApplicant,
888
911
  getS3UrlForAsset,
889
- acceptOrderQCTermsAndConditions
912
+ acceptOrderQCTermsAndConditions,
913
+ runAllValidations: runAllValidationsHandler
890
914
  };
891
915
  return /* @__PURE__ */ jsx(EDCFlowContext.Provider, { value, children });
892
916
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smvtech/x-flux",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "x-flux - A powerful React package for managing effective document collection flows, visa questionnaires, travellers, and applications",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",