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

Develop #72

Merged
merged 21 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
608bfcc
Fix: #134 Adding new columns for export schedule
Dyetrix Jul 6, 2023
2c4af92
feat: Adding tests for schedule-form and user-form
cwtshh Jul 6, 2023
1abe7b7
feat: admin can notify other admins
IanFPFerreira Jul 7, 2023
90c1c6d
test: fix test
IanFPFerreira Jul 7, 2023
b1559c3
Merge pull request #63 from fga-eps-mds/#132-Testes-user-schedula-forms
gabrielavelino Jul 7, 2023
076b432
feat: Adding tests for schedule-edit-form, schedule-open-item and cre…
cwtshh Jul 7, 2023
723d231
Merge pull request #62 from fga-eps-mds/#134_ExportacaoAgendamentos
AlvaroLeles Jul 7, 2023
fded619
Merge pull request #64 from fga-eps-mds/admin_notifica_admin
AlvaroLeles Jul 7, 2023
24d59af
fix: removing bug
italofernandes13 Jul 7, 2023
960d466
Merge pull request #66 from fga-eps-mds/#142-Remover_Bug
guilhermemoraisr Jul 7, 2023
799f84f
Merge pull request #65 from fga-eps-mds/#140-Testes_create-issue-form…
gabrielavelino Jul 8, 2023
fcb47c8
#45 Export report handle file
italovinicius18 Jul 8, 2023
20b73fc
test: increase issues page test coverage
arthurrsousa Jul 8, 2023
1fa427f
Merge pull request #69 from fga-eps-mds/#143-issues-page-test-coverag…
IanFPFerreira Jul 9, 2023
37e04ee
Feat: Adding alert api_status verification
AlvaroLeles Jul 9, 2023
a22e090
Test: Fixing test
AlvaroLeles Jul 9, 2023
bc03382
Test: fixing test
AlvaroLeles Jul 9, 2023
dfe38fc
Merge pull request #70 from fga-eps-mds/#136-api_status_alertas
guilhermemoraisr Jul 9, 2023
6c697a4
fix: #131 removing alert button in homologation and fixing a dateTime…
gabrielbpn Jul 10, 2023
fa35a17
Merge pull request #71 from fga-eps-mds/#131-alertas-homologacao
italofernandes13 Jul 10, 2023
f001ac8
Merge pull request #68 from fga-eps-mds/#45-exportar_relatorio
guilhermemoraisr Jul 10, 2023
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
113 changes: 13 additions & 100 deletions src/components/action-buttons/approve-button-homologation/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useCallback, useState } from 'react';
import { FaPlus, FaTrash } from 'react-icons/fa';
import { useState } from 'react';
import { FaTrash } from 'react-icons/fa';
import {
Box,
Button,
Flex,
Grid,
Divider,
Heading,
Popover,
PopoverAnchor,
Expand All @@ -18,16 +16,15 @@
Text,
useDisclosure,
} from '@chakra-ui/react';
import { Controller, useFieldArray, useForm } from 'react-hook-form';
import { Controller, useForm } from 'react-hook-form';
import { ActionButtonProps } from '../types';
import { ActionButton } from '..';
import { Input } from '@/components/form-fields/input';
import { DeleteButton } from '../delete-button';
import { IssuePayloadOpen } from '@/features/issues/types';
import { parseSelectedDatetime } from '@/utils/format-date';

interface ApproveButtonProps<Data> extends ActionButtonProps<Data> {
handleApproveHomolog: (justify: string) => void;
handleApproveHomolog: (justify: string, dateTime: Date) => void;
passDateTime: Date;
}

Expand All @@ -45,7 +42,7 @@
const { isOpen, onOpen, onClose } = useDisclosure();
const [justification] = useState('');

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

Check warning on line 45 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

Check warning on line 45 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 All @@ -53,22 +50,7 @@
},
});

const { fields, append, remove } = useFieldArray({
control,
shouldUnregister: true,
name: 'problem_types_payload',
});

const handleAddDate = useCallback(() => {
append({ label: '', value: '' });
}, [append]);

const handleRemoveDate = useCallback(
(index: number) => () => {
remove(index);
},
[remove]
);
const dateTime = watch('dateTime');

return (
<Popover isOpen={isOpen} onOpen={onOpen} onClose={onClose} placement="auto">
Expand All @@ -84,6 +66,7 @@
{...props}
/>
</PopoverAnchor>

<PopoverContent
height="200%"
width="150%"
Expand Down Expand Up @@ -126,13 +109,12 @@
}) => (
<>
<Input
{...register('dateTime', {
required: 'Campo obrigatório',
})}
{...register('dateTime')}
label="Data do Evento"
type="datetime-local"
name="dateTime"
id="dateTime"
min={parseSelectedDatetime(String(new Date()))}
onChange={onChange}
ref={ref}
onBlur={onBlur}
Expand All @@ -145,85 +127,16 @@
)}
/>
</Box>
<Box>
<Flex gap={4} alignItems="center" my="0.5rem">
<Text>Alertas</Text>
</Flex>
<Divider mb={4} mt={1} />
<Grid
templateColumns="repeat(auto-fill, minmax(220px, 1fr))"
gap={6}
>
{fields?.map((field, index) => {
return (
<Flex key={field.id} gap={1}>
<Controller
control={control}
name="alerts"
rules={{
min: {
value: new Date().toISOString(),
message: 'Informe uma data no futuro.',
},
required: 'Informe a data ou exclua o alerta',
}}
render={({
field: { onChange, onBlur, ref, value },
fieldState: { error },
}) => (
<Box w="full">
<Input
label="alert_dates"
type="date"
name={`alert_dates.${index}.date`}
id={`alert_dates.${index}.date`}
onChange={onChange}
min={new Date().toISOString()}
ref={ref}
onBlur={onBlur}
w="full"
value={value?.[0]?.toISOString() || ''}
/>
<Text color="red.400" mt=".5rem">
{error ? error.message : null}
</Text>
</Box>
)}
/>

<DeleteButton
label={`Alerta ${index + 1}`}
onClick={handleRemoveDate(index)}
variant="ghost"
alignSelf="flex-end"
_hover={{
backgroundColor: 'blackAlpha.300',
}}
/>
</Flex>
);
})}
</Grid>
<Flex my="0.3rem">
<ActionButton
label="Adicionar Alerta"
icon={<FaPlus />}
variant="outline"
disabled
color="primary"
tooltipProps={{
placement: 'bottom',
}}
onClick={handleAddDate}
/>
</Flex>
</Box>
</PopoverBody>

<PopoverFooter borderBottomRadius="base" border={0} bg="blackAlpha.300">
<Flex justifyContent="space-between">
<Button
onClick={() => props.handleApproveHomolog(justification)}
// only push dateTime if it is bigger than now

onClick={() =>
props.handleApproveHomolog(justification, dateTime)
}
colorScheme="green"
variant="solid"
size="lg"
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', 'USER']}
allowedUsersPath={['ADMIN', 'BASIC']}
/>
</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 !== 'BASIC'
user.profile === 'USER'
? 0
: 1,
}}
Expand Down
9 changes: 9 additions & 0 deletions src/config/routes/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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 @@ -157,6 +158,14 @@ 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: 0 additions & 53 deletions src/features/alerts/api/detele-alerts.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import {
screen,
render,
waitFor,

Check warning on line 4 in src/features/alerts/components/alert-item-manager/alert-item-manager.spec.tsx

View workflow job for this annotation

GitHub Actions / lint

'waitFor' is defined but never used

Check warning on line 4 in src/features/alerts/components/alert-item-manager/alert-item-manager.spec.tsx

View workflow job for this annotation

GitHub Actions / lint

'waitFor' is defined but never used
act,

Check warning on line 5 in src/features/alerts/components/alert-item-manager/alert-item-manager.spec.tsx

View workflow job for this annotation

GitHub Actions / lint

'act' is defined but never used

Check warning on line 5 in src/features/alerts/components/alert-item-manager/alert-item-manager.spec.tsx

View workflow job for this annotation

GitHub Actions / lint

'act' is defined but never used
fireEvent,
} from '@testing-library/react';
import { vi } from 'vitest';
import { AlertItemManager } from '.';
import { Alert } from '../../type';

const mockedNotification: Alert = {
id: '1',
sourceEmail: '[email protected]',
sourceName: 'name',
targetName: 'targetName',
targetEmail: '[email protected]',
message: 'message',
status: 'unsolved',
pendency: 'pending',
read: false,
createdAt: new Date(),
};

const mockedNotificationSolved = {
...mockedNotification,
status: 'solved',
read: true,
};

const mockedNotificationPending = {
...mockedNotification,
status: 'pending',
read: true,
};

const mockedOnDelete = vi.fn(() => {});

describe('AlertItemManager', () => {
it('should render correctly', async () => {
render(
<AlertItemManager
alert={mockedNotification}
onDelete={mockedOnDelete}
isDeleting={false}
/>
);

const targetNameResult = screen.getByText(mockedNotification.targetName);
expect(targetNameResult).toBeInTheDocument();
});

it('should render correctly status pending', async () => {
render(
<AlertItemManager
alert={mockedNotificationPending}
onDelete={mockedOnDelete}
isDeleting={false}
/>
);

const targetNameResult = screen.getByText(
mockedNotificationPending.targetName
);
expect(targetNameResult).toBeInTheDocument();
});

it('should render correctly status solved', async () => {
render(
<AlertItemManager
alert={mockedNotificationSolved}
onDelete={mockedOnDelete}
isDeleting={false}
/>
);

const targetNameResult = screen.queryByText(
mockedNotificationSolved.targetName
);
expect(targetNameResult).toBeInTheDocument();
});

it('should be able to delete a alert', async () => {
const { queryByLabelText } = render(
<AlertItemManager
alert={mockedNotification}
onDelete={mockedOnDelete}
isDeleting={false}
/>
);

const button = queryByLabelText('Alerta');
if (button) {
fireEvent.click(button);
expect(mockedOnDelete).toHaveBeenCalledWith();
}
});
});
10 changes: 8 additions & 2 deletions src/features/alerts/components/alert-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ 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 @@ -62,10 +64,14 @@ export function AlertModal({

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

return (
<Modal title="Criar alerta" size="2xl" onClose={onClose} {...props}>
Expand Down
Loading
Loading