Skip to content

Commit

Permalink
Merge pull request #275 from Tauffer-Consulting/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
vinicvaz authored Apr 9, 2024
2 parents 11ef677 + ab58da8 commit fe9c939
Show file tree
Hide file tree
Showing 31 changed files with 383 additions and 35 deletions.
10 changes: 10 additions & 0 deletions frontend/src/features/auth/api/useAuthLogin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type MutationConfig } from "@services/clients/react-query.client";
import { useMutation } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface LoginParams {
Expand All @@ -20,6 +22,14 @@ export const useAuthLogin = (
return useMutation({
mutationFn: async ({ email, password }) =>
await postAuthLogin({ email, password }),
onError: (e: AxiosError<{ message: string }>) => {
const message =
(e.response?.data?.message ?? e?.message) || "Something went wrong";

toast.error(message, {
toastId: message,
});
},
...config,
});
};
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/features/auth/api/useAuthRegister.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type MutationConfig } from "@services/clients/react-query.client";
import { useMutation } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface RegisterParams {
Expand All @@ -19,6 +21,14 @@ export const useAuthRegister = (
) => {
return useMutation({
mutationFn: async (params) => await postAuthRegister(params),
onError: (e: AxiosError<{ message: string }>) => {
const message =
(e.response?.data?.message ?? e?.message) || "Something went wrong";

toast.error(message, {
toastId: message,
});
},
...config,
});
};
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/features/myWorkflows/api/runs/useRunReport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type QueryConfig } from "@services/clients/react-query.client";
import { skipToken, useQuery } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { type taskState } from "features/myWorkflows/types";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface WorkflowRunReportParams {
Expand Down Expand Up @@ -34,6 +36,18 @@ export const useRunReport = (
? async () =>
await getWorkflowRunReport({ runId, workflowId, workspaceId })
: skipToken,
throwOnError(e, _query) {
const message =
((e as AxiosError<{ detail?: string }>).response?.data?.detail ??
e?.message) ||
"Something went wrong";

toast.error(message, {
toastId: message,
});

return false;
},
...config,
});
};
Expand Down
41 changes: 33 additions & 8 deletions frontend/src/features/myWorkflows/api/runs/useRunTaskLogs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type QueryConfig } from "@services/clients/react-query.client";
import { skipToken, useQuery } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface RunTaskLogsParams {
Expand Down Expand Up @@ -37,14 +39,37 @@ export const useRunTaskLogs = (
queryFn:
!workspaceId || !workflowId || !runId || !taskId || !taskTryNumber
? skipToken
: async () =>
await getWorkflowRunTaskLogs({
workspaceId,
workflowId,
runId,
taskId,
taskTryNumber,
}),
: async () => {
try {
return await getWorkflowRunTaskLogs({
workspaceId,
workflowId,
runId,
taskId,
taskTryNumber,
});
} catch (e) {
console.log(e);
throw e;
}
},
throwOnError(e, _query) {
const message =
((e as AxiosError<{ detail?: string }>).response?.data?.detail ??
e?.message) ||
"Something went wrong";

if (e.response?.status === 404) {
console.log("Logs not found");
return false;
}

toast.error(message, {
toastId: message,
});

return false;
},
...config,
});
};
Expand Down
26 changes: 23 additions & 3 deletions frontend/src/features/myWorkflows/api/runs/useRunTaskResult.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type QueryConfig } from "@services/clients/react-query.client";
import { skipToken, useQuery } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

export interface WorkflowRunTaskResultParams {
Expand Down Expand Up @@ -32,14 +34,32 @@ export const useRunTaskResult = (
queryFn:
!runId || !taskId || !taskTryNumber || !workflowId || !workspaceId
? skipToken
: async () =>
await getWorkflowRunTaskResult({
: async () => {
return await getWorkflowRunTaskResult({
runId,
taskId,
taskTryNumber,
workflowId,
workspaceId,
}),
});
},
throwOnError(e, _query) {
const message =
((e as AxiosError<{ detail?: string }>).response?.data?.detail ??
e?.message) ||
"Something went wrong";

if (e?.response?.status === 404) {
console.log("Results not found");
return false;
}

toast.error(message, {
toastId: message,
});

return false;
},
...config,
});
};
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/features/myWorkflows/api/runs/useRunTasks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type IWorkflowRunTasks } from "@features/myWorkflows/types";
import { type InfiniteQueryConfig } from "@services/clients/react-query.client";
import { useInfiniteQuery } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface WorkflowRunTasksParams {
Expand Down Expand Up @@ -39,6 +41,18 @@ export const useRunTasks = (
enabled: !!(workspaceId && workflowId && runId),
getNextPageParam: (res, _, page) =>
(res.metadata?.last_page ?? 0) > page ? page + 1 : null,
throwOnError(e, _query) {
const message =
((e as AxiosError<{ detail?: string }>).response?.data?.detail ??
e?.message) ||
"Something went wrong";

toast.error(message, {
toastId: message,
});

return false;
},
...config,
});
};
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/features/myWorkflows/api/runs/useRuns.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type IWorkflowRuns } from "@features/myWorkflows/types";
import { type QueryConfig } from "@services/clients/react-query.client";
import { skipToken, useQuery } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface WorkflowRunParams {
Expand All @@ -26,6 +28,18 @@ export const useRuns = (
? skipToken
: async () =>
await getWorkflowRuns({ workspaceId, workflowId, page, pageSize }),
throwOnError(e, _query) {
const message =
((e as AxiosError<{ detail?: string }>).response?.data?.detail ??
e?.message) ||
"Something went wrong";

toast.error(message, {
toastId: message,
});

return false;
},
...config,
});
};
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/features/myWorkflows/api/runs/useStartRun.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type MutationConfig } from "@services/clients/react-query.client";
import { useMutation } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { type IPostWorkflowRunIdResponseInterface } from "features/myWorkflows/types/workflow";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface StartRunParams {
Expand All @@ -23,6 +25,14 @@ export const useStartRun = (
if (!workflowId) throw new Error("no workspace selected");
return await postWorkflowRunId({ workflowId, workspaceId });
},
onError: (e: AxiosError<{ detail: string }>) => {
const message =
(e.response?.data?.detail ?? e?.message) || "Something went wrong";

toast.error(message, {
toastId: message,
});
},
...config,
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type MutationConfig } from "@services/clients/react-query.client";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { type IDeleteWorkflowIdResponseInterface } from "features/myWorkflows/types/workflow";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface DeleteWorkflowParams {
Expand Down Expand Up @@ -30,6 +32,14 @@ export const useDeleteWorkflow = (
queryKey: ["WORKFLOW", workspaceId, workflowId],
});
},
onError: (e: AxiosError<{ detail: string }>) => {
const message =
(e.response?.data?.detail ?? e?.message) || "Something went wrong";

toast.error(message, {
toastId: message,
});
},
...config,
});
};
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/features/myWorkflows/api/workflow/useWorkflow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type QueryConfig } from "@services/clients/react-query.client";
import { useQuery, skipToken } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { type IGetWorkflowIdResponseInterface } from "features/myWorkflows/types/workflow";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface GetWorkflowByIdParams {
Expand All @@ -18,6 +20,18 @@ export const useWorkflow = (
workspaceId && workflowId
? async () => await getWorkflowById({ workflowId, workspaceId })
: skipToken,
throwOnError(e, _query) {
const message =
((e as AxiosError<{ detail?: string }>).response?.data?.detail ??
e?.message) ||
"Something went wrong";

toast.error(message, {
toastId: message,
});

return false;
},
...config,
});
};
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/features/myWorkflows/api/workflow/useWorkflows.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type QueryConfig } from "@services/clients/react-query.client";
import { useQuery, skipToken } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { type IGetWorkflowResponseInterface } from "features/myWorkflows/types/workflow";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface GetWorkflowsParams {
Expand All @@ -18,6 +20,18 @@ export const useWorkflows = (
queryFn: workspaceId
? async () => await getWorkflows({ workspaceId, page, pageSize })
: skipToken,
throwOnError(e, _query) {
const message =
((e as AxiosError<{ detail?: string }>).response?.data?.detail ??
e?.message) ||
"Something went wrong";

toast.error(message, {
toastId: message,
});

return false;
},
...config,
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { type MutationConfig } from "@services/clients/react-query.client";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { type AxiosError } from "axios";
import { type IPostWorkflowResponseInterface } from "features/myWorkflows/types";
import { type CreateWorkflowRequest } from "features/workflowEditor/context/types";
import { toast } from "react-toastify";
import { dominoApiClient } from "services/clients/domino.client";

interface UsePostWorkflow {
Expand All @@ -27,6 +29,14 @@ export const useCreateWorkflow = (
queryKey: ["WORKFLOWS", workspaceId],
});
},
onError: (e: AxiosError<{ detail: string }>) => {
const message =
(e.response?.data?.detail ?? e?.message) || "Something went wrong";

toast.error(message, {
toastId: message,
});
},
...config,
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { type QueryConfig } from "@services/clients/react-query.client";
import { useQuery, skipToken } from "@tanstack/react-query";
import axios from "axios";
import axios, { type AxiosError } from "axios";
import { type WorkflowPieceData } from "features/workflowEditor/context/types";
import { toast } from "react-toastify";
import { type Edge, type Node } from "reactflow";

interface JSONFile {
Expand All @@ -25,6 +26,18 @@ export const useWorkflowsExamples = (
return useQuery({
queryKey: ["WORKFLOWS-EXAMPLES"],
queryFn: fetch ? async () => await getWorkflowsExample() : skipToken,
throwOnError(e, _query) {
const message =
((e as AxiosError<{ detail?: string }>).response?.data?.detail ??
e?.message) ||
"Something went wrong";

toast.error(message, {
toastId: message,
});

return false;
},
...config,
});
};
Expand Down
Loading

0 comments on commit fe9c939

Please sign in to comment.