Skip to content

Commit

Permalink
Merge pull request #55 from fga-eps-mds/refactor/services
Browse files Browse the repository at this point in the history
refactor/services
  • Loading branch information
senaarth authored Jul 30, 2023
2 parents 3dca6d8 + 72a034a commit bcff673
Show file tree
Hide file tree
Showing 47 changed files with 370 additions and 330 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ jobs:
test:
runs-on: ubuntu-latest
env:
VITE_API_SERVICE_URL: ${{ secrets.VITE_API_SERVICE_URL }}
VITE_USER_SERVICE_URL: ${{ secrets.VITE_USER_SERVICE_URL }}
VITE_UNITS_SERVICE_URL: ${{ secrets.VITE_UNITS_SERVICE_URL }}
VITE_STAGES_SERVICE_URL: ${{ secrets.VITE_STAGES_SERVICE_URL }}
VITE_PROCESSES_SERVICE_URL: ${{ secrets.VITE_PROCESSES_SERVICE_URL }}
VITE_FLOWS_SERVICE_URL: ${{ secrets.VITE_FLOWS_SERVICE_URL }}
VITE_ROLE_SERVICE_URL: ${{ secrets.VITE_ROLE_SERVICE_URL }}
VITE_UNIT_SERVICE_URL: ${{ secrets.VITE_UNIT_SERVICE_URL }}
VITE_PROCESS_MANAGEMENT_SERVICE_URL: ${{ secrets.VITE_PROCESS_MANAGEMENT_SERVICE_URL }}
VITE_NOTE_SERVICE_URL: ${{ secrets.VITE_NOTE_SERVICE_URL }}
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -158,12 +157,11 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: true
env:
VITE_API_SERVICE_URL: ${{ secrets.VITE_API_SERVICE_URL }}
VITE_USER_SERVICE_URL: ${{ secrets.VITE_USER_SERVICE_URL }}
VITE_UNITS_SERVICE_URL: ${{ secrets.VITE_UNITS_SERVICE_URL }}
VITE_STAGES_SERVICE_URL: ${{ secrets.VITE_STAGES_SERVICE_URL }}
VITE_PROCESSES_SERVICE_URL: ${{ secrets.VITE_PROCESSES_SERVICE_URL }}
VITE_FLOWS_SERVICE_URL: ${{ secrets.VITE_FLOWS_SERVICE_URL }}
VITE_ROLE_SERVICE_URL: ${{ secrets.VITE_ROLE_SERVICE_URL }}
VITE_UNIT_SERVICE_URL: ${{ secrets.VITE_UNIT_SERVICE_URL }}
VITE_PROCESS_MANAGEMENT_SERVICE_URL: ${{ secrets.VITE_PROCESS_MANAGEMENT_SERVICE_URL }}
VITE_NOTE_SERVICE_URL: ${{ secrets.VITE_NOTE_SERVICE_URL }}
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ O CAPJu é uma aplicação _Web_ compatível com qualquer navegador.
Configure o arquivo .env.local dos repositório igual abaixo:

```
VITE_API_SERVICE_URL=
VITE_USER_SERVICE_URL=
VITE_UNITS_SERVICE_URL=
VITE_STAGES_SERVICE_URL=
VITE_PROCESSES_SERVICE_URL=
VITE_FLOWS_SERVICE_URL=
VITE_ROLE_SERVICE_URL=
VITE_UNIT_SERVICE_URL=
VITE_PROCESS_MANAGEMENT_SERVICE_URL=
VITE_NOTE_SERVICE_URL=
```

Obs: é necessário ser igual ao back-end.
Expand Down
2 changes: 1 addition & 1 deletion src/components/Flow/CommentEdge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { MdDelete, MdEdit } from "react-icons/md";
import { ViewIcon } from "@chakra-ui/icons";

import { addNoteToProcess, deleteProcessNote } from "services/processes";
import { addNoteToProcess, deleteProcessNote } from "services/note";
import { useLoading } from "hooks/useLoading";
import { AddModal } from "./AddModal";
import { DeletionModal } from "./DeletionModal";
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
useCallback,
} from "react";

import { signIn, getUserById, getRoleById } from "services/user";
import { signIn, getUserById } from "services/user";
import { getRoleById } from "services/role";

type AuthContextType = {
isAuthenticated: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Flows/CreationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import * as yup from "yup";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";

import { createFlow } from "services/flows";
import { getStages } from "services/stages";
import { createFlow } from "services/processManagement/flows";
import { getStages } from "services/processManagement/stage";
import { getAcceptedUsers } from "services/user";
import { Input, MultiSelect } from "components/FormFields";
import { Flow } from "components/Flow";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Flows/DeletionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Text,
useToast,
} from "@chakra-ui/react";
import { deleteFlow } from "services/flows";
import { deleteFlow } from "services/processManagement/flows";
import { useLoading } from "hooks/useLoading";

interface DeletionModalProps {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Flows/EditionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import * as yup from "yup";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";

import { updateFlow } from "services/flows";
import { getStages } from "services/stages";
import { updateFlow } from "services/processManagement/flows";
import { getStages } from "services/processManagement/stage";
import { getAcceptedUsers } from "services/user";
import { Input, MultiSelect } from "components/FormFields";
import { Flow } from "components/Flow";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Flows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AddIcon, Icon, ViewIcon, SearchIcon } from "@chakra-ui/icons";
import { createColumnHelper } from "@tanstack/react-table";

import { PrivateLayout } from "layouts/Private";
import { getFlows } from "services/flows";
import { getFlows } from "services/processManagement/flows";
import { DataTable } from "components/DataTable";
import { Input } from "components/FormFields";
import { useAuth } from "hooks/useAuth";
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Processes/CreationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { yupResolver } from "@hookform/resolvers/yup";

import { Input, Select } from "components/FormFields";
import { useLoading } from "hooks/useLoading";
import { getPriorities } from "services/priorities";
import { getFlows } from "services/flows";
import { createProcess } from "services/processes";
import { getPriorities } from "services/processManagement/priority";
import { getFlows } from "services/processManagement/flows";
import { createProcess } from "services/processManagement/processes";

type FormValues = {
record: string;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Processes/DeletionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Text,
useToast,
} from "@chakra-ui/react";
import { deleteProcess } from "services/processes";
import { deleteProcess } from "services/processManagement/processes";
import { useLoading } from "hooks/useLoading";

interface DeletionModalProps {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Processes/EditionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { yupResolver } from "@hookform/resolvers/yup";

import { Input, Select } from "components/FormFields";
import { useLoading } from "hooks/useLoading";
import { getPriorities } from "services/priorities";
import { getFlows } from "services/flows";
import { updateProcess } from "services/processes";
import { getPriorities } from "services/processManagement/priority";
import { getFlows } from "services/processManagement/flows";
import { updateProcess } from "services/processManagement/processes";

type FormValues = {
record: string;
Expand Down
48 changes: 15 additions & 33 deletions src/pages/Processes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { createColumnHelper } from "@tanstack/react-table";
import { useLocation, useNavigate } from "react-router-dom";
import { IoReturnDownBackOutline } from "react-icons/io5";

import { getProcesses } from "services/processes";
import { getFlows } from "services/flows";
import { getProcesses } from "services/processManagement/processes";
import { getFlows } from "services/processManagement/flows";
import { isActionAllowedToUser } from "utils/permissions";
import { useAuth } from "hooks/useAuth";
import { PrivateLayout } from "layouts/Private";
Expand All @@ -49,7 +49,7 @@ function Processes() {
});
const [filter, setFilter] = useState<string | undefined>(undefined);
const [legalPriority, setLegalPriority] = useState(false);
const [showFinished, setShowFinished] = useState<boolean>(true);
const [showFinished, setShowFinished] = useState(false);
const {
isOpen: isCreationOpen,
onOpen: onCreationOpen,
Expand All @@ -72,7 +72,7 @@ function Processes() {
const { data: flowsData, isFetched: isFlowsFetched } = useQuery({
queryKey: ["flows"],
queryFn: async () => {
const res = await getFlows(undefined, filter);
const res = await getFlows();

if (res.type === "error") throw new Error(res.error.message);

Expand Down Expand Up @@ -102,7 +102,9 @@ function Processes() {
offset: currentPage * 5,
limit: 5,
},
filter
filter,
legalPriority,
showFinished
);

if (res.type === "error") throw new Error(res.error.message);
Expand Down Expand Up @@ -161,28 +163,11 @@ function Processes() {
],
[isProcessesFetched, isUserFetched, userData]
);
const filterByPriority = (processes: Process[]) =>
processes?.filter((process: Process) => process.idPriority);

const filterByStatus = (processes: Process[]) => {
if (!showFinished) {
return processes?.filter(
(process: Process) =>
process.status === "finished" || process.status === "archived"
);
}
return processes;
};
const filteredProcesses = useMemo<TableRow<Process>[]>(() => {
const processesTableRows = useMemo<TableRow<Process>[]>(() => {
if (!isProcessesFetched || !isFlowsFetched) return [];

let value = processesData?.value;

if (legalPriority && value) value = filterByPriority(value);
if (!showFinished && value) value = filterByStatus(value);

return (
(value?.reduce(
(processesData?.value?.reduce(
(
acc: TableRow<Process>[] | Process[],
curr: TableRow<Process> | Process
Expand Down Expand Up @@ -245,16 +230,13 @@ function Processes() {
) as TableRow<Process>[]) || []
);
}, [
legalPriority,
showFinished,
processesData,
filter,
isProcessesFetched,
isUserFetched,
userData,
tableActions,
isUserFetched,
flowsData,
isFlowsFetched,
isProcessesFetched,
tableActions,
]);

const tableColumnHelper = createColumnHelper<TableRow<any>>();
Expand Down Expand Up @@ -306,7 +288,7 @@ function Processes() {

useEffect(() => {
refetchProcesses();
}, [flowsData, isFlowsFetched, currentPage]);
}, [flowsData, isFlowsFetched, currentPage, showFinished, legalPriority]);

return (
<PrivateLayout>
Expand Down Expand Up @@ -396,13 +378,13 @@ function Processes() {
checked={showFinished}
onChange={() => setShowFinished(!showFinished)}
>
Mostrar apenas processos arquivados/finalizados
Mostrar processos arquivados/finalizados
</Checkbox>
</Flex>
</Flex>
</Flex>
<DataTable
data={filteredProcesses}
data={processesTableRows}
columns={tableColumns}
isDataFetching={!isProcessesFetched || !isUserFetched}
emptyTableMessage={`Não foram encontrados processos${
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProfilesActionsManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

import { PrivateLayout } from "layouts/Private";
import { actionsForm } from "utils/permissions";
import { getAllRoles, updateRoleAllowedActions } from "services/user";
import { updateRoleAllowedActions, getAllRoles } from "services/role";
import { useLoading } from "hooks/useLoading";

function ProfilesActionsManager() {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/ProfilesManager/Profiles/EditionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import * as yup from "yup";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";

import { getAllRoles, updateUserRole } from "services/user";
import { updateUserRole } from "services/user";
import { getAllRoles } from "services/role";
import { Select } from "components/FormFields/Select";
import { useLoading } from "hooks/useLoading";

Expand Down
5 changes: 3 additions & 2 deletions src/pages/ProfilesManager/Profiles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { MdEdit, MdDelete } from "react-icons/md";
import { createColumnHelper } from "@tanstack/react-table";

import { DataTable } from "components/DataTable";
import { getAcceptedUsers, getAllRoles } from "services/user";
import { getAcceptedUsers } from "services/user";
import { getAllRoles } from "services/role";
import { Input } from "components/FormFields";
import { useAuth } from "hooks/useAuth";
import { isActionAllowedToUser } from "utils/permissions";
import { getUnits } from "services/units";
import { getUnits } from "services/unit";
import { Pagination } from "components/Pagination";
import { DeletionModal } from "./DeletionModal";
import { EditionModal } from "./EditionModal";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProfilesManager/Requests/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DataTable } from "components/DataTable";
import { Input } from "components/FormFields";
import { useAuth } from "hooks/useAuth";
import { isActionAllowedToUser } from "utils/permissions";
import { getUnits } from "services/units";
import { getUnits } from "services/unit";
import { Pagination } from "components/Pagination";
import { getUsersRequests } from "services/user";
import { AcceptModal } from "./AcceptModal";
Expand Down
5 changes: 3 additions & 2 deletions src/pages/Signup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import _ from "lodash";

import { useLoading } from "hooks/useLoading";
import { Input } from "components/FormFields";
import { getUnits } from "services/units";
import { getUnits } from "services/unit";
import { Select } from "components/FormFields/Select";
import { getAllRoles, signUp } from "services/user";
import { signUp } from "services/user";
import { getAllRoles } from "services/role";
import { validateCPF } from "utils/validators";

type FormValues = {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Stages/CreationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { yupResolver } from "@hookform/resolvers/yup";

import { Input } from "components/FormFields";
import { useLoading } from "hooks/useLoading";
import { createStage } from "../../../services/stages";
import { createStage } from "../../../services/processManagement/stage";

type FormValues = {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Stages/DeletionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Text,
useToast,
} from "@chakra-ui/react";
import { deleteStage } from "services/stages";
import { deleteStage } from "services/processManagement/stage";
import { useLoading } from "hooks/useLoading";

interface DeletionModalProps {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Stages/EditionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as yup from "yup";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";

import { updateStage } from "services/stages";
import { updateStage } from "services/processManagement/stage";
import { Input } from "components/FormFields";
import { useLoading } from "hooks/useLoading";

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Stages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { DataTable } from "components/DataTable";
import { Input } from "components/FormFields";
import { isActionAllowedToUser } from "utils/permissions";
import { Pagination } from "components/Pagination";
import { getStages } from "../../services/stages";
import { getStages } from "../../services/processManagement/stage";
import { CreationModal } from "./CreationModal";
import { DeletionModal } from "./DeletionModal";
import { EditionModal } from "./EditionModal";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Units/CreationModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as yup from "yup";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";

import { createUnit } from "services/units";
import { createUnit } from "services/unit";
import { Input } from "components/FormFields";
import { useLoading } from "hooks/useLoading";

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Units/DeletionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Text,
useToast,
} from "@chakra-ui/react";
import { deleteUnit } from "services/units";
import { deleteUnit } from "services/unit";
import { useLoading } from "hooks/useLoading";

interface DeletionModalProps {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Units/EditionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as yup from "yup";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";

import { updateUnit } from "services/units";
import { updateUnit } from "services/unit";
import { Input } from "components/FormFields";
import { useLoading } from "hooks/useLoading";

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Units/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MdDelete, MdEdit } from "react-icons/md";
import { createColumnHelper } from "@tanstack/react-table";

import { PrivateLayout } from "layouts/Private";
import { getUnits } from "services/units";
import { getUnits } from "services/unit";
import { DataTable } from "components/DataTable";
import { Input } from "components/FormFields";
import { useAuth } from "hooks/useAuth";
Expand Down
Loading

0 comments on commit bcff673

Please sign in to comment.