@betterinternship/components 1.4.1 → 1.4.3

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.
@@ -22,7 +22,10 @@ export declare function useClientProcess<T, R>({ caller, loadingMessage, success
22
22
  successMessage?: string;
23
23
  failureMessage?: string;
24
24
  }): {
25
- run: (inputs: T) => Promise<void>;
25
+ run: (inputs: T) => Promise<{
26
+ success: boolean;
27
+ message: string | undefined;
28
+ }>;
26
29
  attempts: number;
27
30
  status: ProcessStatus;
28
31
  result: unknown;
package/dist/index.esm.js CHANGED
@@ -3718,25 +3718,35 @@ function useClientProcess({ caller, loadingMessage, successMessage, failureMessa
3718
3718
  return;
3719
3719
  // Update toast to show current state
3720
3720
  if (clientProcess.status === 'pending') {
3721
+ console.log(response.processName, loadingMessage ?? "Loading...");
3721
3722
  toast.loading(loadingMessage ?? "Loading...", {
3722
3723
  id: response.processId,
3723
3724
  duration: Infinity,
3724
3725
  });
3725
3726
  }
3726
3727
  else if (clientProcess.status === 'failed') {
3728
+ console.error(response.processName, failureMessage ?? "Something went wrong.");
3727
3729
  toast.error(failureMessage ?? "Something went wrong.", {
3728
3730
  id: response.processId
3729
3731
  });
3730
3732
  }
3731
3733
  else if (clientProcess.status === 'handled') {
3734
+ console.warn(response.processName, successMessage ?? "Success!");
3732
3735
  toast.success(successMessage ?? "Success!", {
3733
3736
  id: response.processId
3734
3737
  });
3735
3738
  }
3736
3739
  }, [response, clientProcess]);
3740
+ // Note that the exposed function doesn't return process ids
3741
+ // Client should be oblivious to those
3742
+ // Abstraction BABY!
3737
3743
  const wrappedCaller = async (inputs) => {
3738
3744
  const response = await caller(inputs);
3739
3745
  setResponse(response);
3746
+ return {
3747
+ success: response.success,
3748
+ message: response.message,
3749
+ };
3740
3750
  };
3741
3751
  return {
3742
3752
  run: wrappedCaller,