Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#45 exportar relatorios #67

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metrics/sonar-metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def generate_metrics():
repository_version = sys.argv[2]
underlined_repo_name = repository_name[:16] + \
repository_name[16:].replace('-', "_")
url = f'{base_url}{repository_name}&metricKeys={",".join(metrics)}&ps=500'
url = f'{base_url}{repository_name}&metricKeys={",".join(metrics)}'
with urllib.request.urlopen(url) as res:
data = json.load(res)
date = datetime.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
const { isOpen, onOpen, onClose } = useDisclosure();
const [justification] = useState('');

const [isLoading, setIsLoading] = useState(false);

Check warning on line 48 in src/components/action-buttons/approve-button-homologation/index.tsx

View workflow job for this annotation

GitHub Actions / lint

'setIsLoading' is assigned a value but never used

const { control, watch, register } = useForm<IssuePayloadOpen>({
defaultValues: {
Expand Down Expand Up @@ -209,7 +209,6 @@
label="Adicionar Alerta"
icon={<FaPlus />}
variant="outline"
disabled
color="primary"
tooltipProps={{
placement: 'bottom',
Expand Down
2 changes: 1 addition & 1 deletion src/components/side-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const SideBar = memo(() => {
label="Notificações"
pathname="/notificacoes"
icon={AiOutlineBell}
allowedUsersPath={['ADMIN', 'BASIC']}
allowedUsersPath={['ADMIN', 'BASIC', 'USER']}
/>
</Box>
<Box shadow="xl" p=".5rem">
Expand Down
2 changes: 1 addition & 1 deletion src/components/side-bar/sidebar-notification/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const SideBarNotification = memo(
style={{
opacity:
filteredNotifications?.length === 0 ||
user.profile === 'USER'
user.profile !== 'BASIC'
? 0
: 1,
}}
Expand Down
9 changes: 0 additions & 9 deletions src/config/routes/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { RegistrarAgendamento } from '@/pages/agendamento_externo/index';
import { AgendamentosAbertos } from '@/pages/agendamentos_abertos';
import { DefaultLayoutOpen } from '@/components/layout/default-layout-open';
import { Notificacoes } from '@/pages/notificacoes';
import { NotificacaoAdmin } from '@/pages/notificacoes/notificacoes_admin';

export function Router() {
return (
Expand Down Expand Up @@ -158,14 +157,6 @@ export function Router() {
</RequireAuth>
}
/>
<Route
path="notificacoes/notificacoes_admin"
element={
<RequireAuth>
<NotificacaoAdmin />
</RequireAuth>
}
/>
</Route>
{/* ROTAS PUBLICAS */}
<Route path="/login" element={<Login />} />
Expand Down
53 changes: 53 additions & 0 deletions src/features/alerts/api/detele-alerts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { api } from '@/config/lib/axios';
import { ALERT_ENDPOINT } from '@/features/alerts/constants/requests';
import { toast } from '@/utils/toast';
import { ALERTS_CACHE_KEYS } from '@/features/alerts/constants/cache';
import {
DeleteAlertParams,
DeleteAlertsParams,
} from '@/features/alerts/api/types';

function deleteAlert({ alertId }: DeleteAlertParams) {
return api.delete<boolean>(`${ALERT_ENDPOINT}/notifications/${alertId}`);
}

function deleteAlerts({ alertsIds }: DeleteAlertsParams) {
return api.delete<boolean>(
`${ALERT_ENDPOINT}/notifications/delete-alerts/${alertsIds}`
);
}

export function useDeleteAlert() {
const queryClient = useQueryClient();

return useMutation(deleteAlert, {
onSuccess() {
toast.success('Alerta removido com sucesso!');

queryClient.invalidateQueries([ALERTS_CACHE_KEYS.allAlerts]);
},
onError() {
toast.error(
'Não foi possível remover o alerta. Tente novamente mais tarde!'
);
},
});
}

export function useDeleteAlerts() {
const queryClient = useQueryClient();

return useMutation(deleteAlerts, {
onSuccess() {
toast.success('Alerta removidos com sucesso!');

queryClient.invalidateQueries([ALERTS_CACHE_KEYS.allAlerts]);
},
onError() {
toast.error(
'Não foi possível remover os alerta. Tente novamente mais tarde!'
);
},
});
}

This file was deleted.

10 changes: 2 additions & 8 deletions src/features/alerts/components/alert-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export function AlertModal({
const [filterBasicUsers, setFilterBasicUsers] = useState(users || []);
const { user } = useAuth();

const userAuth = useAuth();

const handleSubmit = useCallback(
async ({ target, message }: AlertPayload) => {
const { label, value } = target;
Expand Down Expand Up @@ -64,14 +62,10 @@ export function AlertModal({

useEffect(() => {
if (users) {
const filteredUsers = users.filter(
(user) =>
(user.profile === 'BASIC' || user.profile === 'ADMIN') &&
user.email !== userAuth.user?.email
);
const filteredUsers = users.filter((user) => user.profile === 'BASIC');
setFilterBasicUsers(filteredUsers);
}
}, [users, userAuth.user?.email]);
}, [users]);

return (
<Modal title="Criar alerta" size="2xl" onClose={onClose} {...props}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
value: locate.state.problem_category.id ?? '',
},
problem_types_payload:
externIssue?.problem_types.map((type: { name: string; id: any }) => ({

Check warning on line 64 in src/features/homologations/components/issue-open-edit-form/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
label: type.name,
value: type.id,
})) || [],
Expand Down Expand Up @@ -438,7 +438,6 @@
label="Adicionar Alerta"
icon={<FaPlus />}
variant="outline"
disabled
color="primary"
tooltipProps={{
placement: 'bottom',
Expand Down
22 changes: 1 addition & 21 deletions src/features/issues/components/issue-item/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Badge,
Box,
Button,
HStack,
Spacer,
Tag,
Expand All @@ -15,32 +14,19 @@ import { useGetAllCities } from '@/features/cities/api/get-all-cities';
import { DeleteButton } from '@/components/action-buttons/delete-button';
import { ItemActions } from '@/components/list-item/list-item-actions';
import { Permission } from '@/components/permission';
import { useGetAllSchedules } from '@/features/schedules/api/get-all-schedules';

interface IssueItemProps {
issue: Issue;
onDelete: (issueId: string) => void;
isDeleting: boolean;
onOpen?: () => void;
}

export function IssueItem({
issue,
onDelete,
isDeleting,
onOpen,
}: IssueItemProps) {
export function IssueItem({ issue, onDelete, isDeleting }: IssueItemProps) {
const { data: cities } = useGetAllCities(0);
const city = cities?.find((city) => {
return city?.id === issue?.city_id;
});

const { data: schedules } = useGetAllSchedules();

const isIssueScheduled = schedules?.some(
(schedule) => schedule.issue.id === issue.id
);

return (
<Box>
<HStack spacing={2}>
Expand Down Expand Up @@ -121,12 +107,6 @@ export function IssueItem({
}}
>
<ItemActions item={city}>
{!isIssueScheduled ? (
<Button onClick={onOpen}>Gerar Agendamento</Button>
) : (
(null as any)
)}

<DeleteButton
onClick={() => onDelete(issue.id)}
label="atendimento"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('IssueItem', () => {
expect(name[0]).toBeInTheDocument();
});

it.todo('should be able to delete a item', async () => {
it('should be able to delete a item', async () => {
const { queryByLabelText } = render(
<QueryClientProvider client={queryClient}>
<IssueItem
Expand Down
2 changes: 1 addition & 1 deletion src/features/notifications/api/get-all-notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getAllNotifications = async () =>
const errMessage =
err?.response?.data?.message ??
'Não foi possível carregar as notificações. Tente novamente mais tarde!';
// toast.error(errMessage);
toast.error(errMessage);
return [] as GetAllNotificationsResponse;
});

Expand Down
38 changes: 38 additions & 0 deletions src/features/reports/api/get-report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { api } from '@/config/lib/axios';
import { REPORT_ENDPOINT } from '@/features/reports/constants/requests';
import { GetReportParams, GetReportResponse } from '@/features/reports/types';
import { toast } from '@/utils/toast';
import { REPORT_CACHE_KEYS } from '@/features/reports/constants/cache';

const getReport = async ({ startDate, endDate }: GetReportParams) =>
api
.get<GetReportResponse>(
`${REPORT_ENDPOINT}/report/?startDate=${startDate}&endDate=${endDate}`
)
.then((response) => {
return response.data;
})
.catch((error) => {
toast.error(
'Não foi possível carregar o relatório. Tente novamente mais tarde!'
);
return error;
});

// Set this with mutation
export const useGetReport = ({
onSuccessCallBack,
}: {
onSuccessCallBack?: () => void;
}) => {
const queryClient = useQueryClient();

return useMutation(getReport, {
onSuccess() {
queryClient.invalidateQueries([REPORT_CACHE_KEYS.reportsCache]);

onSuccessCallBack?.();
},
});
};
3 changes: 3 additions & 0 deletions src/features/reports/constants/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum REPORT_CACHE_KEYS {
reportsCache = 'report-cache',
}
2 changes: 2 additions & 0 deletions src/features/reports/constants/requests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const REPORT_ENDPOINT =
import.meta.env.VITE_PUBLIC_DETALHADOR_CHAMADOS_URL ?? '';
9 changes: 9 additions & 0 deletions src/features/reports/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface GetReportParams {
startDate: string | null;
endDate: string | null;
}

export interface GetReportResponse {
type: string;
data: ArrayBuffer;
}
5 changes: 3 additions & 2 deletions src/features/schedules/components/schedule-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ export function ScheduleForm({
applicant_phone={issue?.phone ?? ''}
city={city?.name ?? ''}
problem={
issue?.problem_types.map((problem) => problem.name).join(' - ') ??
''
issue?.problem_category.problem_types
.map((problem) => problem.name)
.join(' - ') ?? ''
}
category={issue?.problem_category.name ?? ''}
workstation={workstation ?? ''}
Expand Down
Loading
Loading