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

Conferences and journals refresh button added [RES-25] #21

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions src/assets/icons/AddIcon.svg

This file was deleted.

61 changes: 50 additions & 11 deletions src/components/CustomToolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,66 @@ import {
} from '@mui/x-data-grid';
import { AuthUtils } from '@cincoders/cinnamon';
import { useAuth } from 'react-oidc-context';
import AddIcon from '../../assets/icons/AddIcon.svg';
import { useState } from 'react';
import AddIcon from '@mui/icons-material/Add';
import RefreshIcon from '@mui/icons-material/Refresh';
import { Roles } from '../../types/enums';

interface CustomToolbarProps {
onCreateClick: () => void;
onUpdateClick: () => Promise<void>;
}
interface CreateButtonProps {
onCreateClick: () => void;
}

interface UpdateButtonProps {
onUpdateClick: () => Promise<void>;
}

export function CreateButton({ onCreateClick }: CustomToolbarProps) {
export function UpdateButton({ onUpdateClick }: UpdateButtonProps) {
const [isRotating, setIsRotating] = useState(false);

const handleClick = () => {
setIsRotating(true);
onUpdateClick().then(() => setIsRotating(false));
};

return (
<Button type='button' onClick={handleClick}>
<RefreshIcon
sx={{
animation: isRotating ? 'rotation 1s linear infinite' : 'none',
'@keyframes rotation': {
from: {
transform: 'rotate(0deg)',
},
to: {
transform: 'rotate(359deg)',
},
},
fontSize: '28px',
color: '#DC412F',
marginRight: '2px',
}}
/>
Atualizar
<span className='css-8je8zh-MuiTouchRipple-root' />
</Button>
);
}

export function CreateButton({ onCreateClick }: CreateButtonProps) {
return (
<Button type='button' onClick={onCreateClick}>
<span className='MuiButton-startIcon MuiButton-iconSizeSmall css-y6rp3m-MuiButton-startIcon'>
<img src={AddIcon} alt='Icone criar' style={{ width: '18px', height: '18px', marginBottom: 1 }} />
</span>
<AddIcon sx={{ color: '#DC412F', fontSize: '32px', marginRight: '2px' }} />
Criar
<span className='css-8je8zh-MuiTouchRipple-root' />
</Button>
);
}

export function CustomToolbar({ onCreateClick }: CustomToolbarProps) {
export function CustomToolbar({ onCreateClick, onUpdateClick }: CustomToolbarProps) {
const auth = useAuth();
return (
<GridToolbarContainer>
Expand All @@ -35,11 +75,10 @@ export function CustomToolbar({ onCreateClick }: CustomToolbarProps) {
<GridToolbarDensitySelector />
<GridToolbarExport />
</Grid>
{onCreateClick && AuthUtils.hasAccess(auth, [Roles.ADMIN]) && (
<Grid sx={{ marginLeft: 'auto' }}>
<CreateButton onCreateClick={onCreateClick} />
</Grid>
)}
<Grid sx={{ marginLeft: 'auto' }}>
{onCreateClick && AuthUtils.hasAccess(auth, [Roles.ADMIN]) && <CreateButton onCreateClick={onCreateClick} />}
{onUpdateClick && AuthUtils.hasAccess(auth, [Roles.ADMIN]) && <UpdateButton onUpdateClick={onUpdateClick} />}
</Grid>
</GridToolbarContainer>
);
}
25 changes: 24 additions & 1 deletion src/pages/Qualis/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ function Table() {

const handleCreateClick = () => setOpen(true);

const handleUpdateClick = async () => {
try {
const [conferencesResp, journalsResp] = await Promise.all([
QualisService.refreshConferences(),
QualisService.refreshJournals(),
]);

if (conferencesResp.status !== 201 || journalsResp.status !== 201) {
throw new Error('Erro ao atualizar conferências e periódicos.');
}

toast.success('Conferências e periódicos atualizados com sucesso!', {
containerId: 'page',
position: 'top-right',
});
} catch (error) {
toast.error('Ocorreu um erro ao atualizar conferências e periódicos. Tente novamente mais tarde.', {
containerId: 'page',
position: 'top-right',
});
}
};

const handleCellEditCommit = React.useCallback(
async params => {
const { id, field, value } = params;
Expand Down Expand Up @@ -171,7 +194,7 @@ function Table() {
[checkedConferences],
);

const toolbarClick = () => <CustomToolbar onCreateClick={handleCreateClick} />;
const toolbarClick = () => <CustomToolbar onCreateClick={handleCreateClick} onUpdateClick={handleUpdateClick} />;

useEffect(() => {
async function loadData() {
Expand Down
10 changes: 10 additions & 0 deletions src/services/QualisService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ export class QualisService {
const response = await apiBack.post('qualis/journals/', journalQualisDTO);
return response;
}

static async refreshConferences(): Promise<AxiosResponse<ConferencesQualis[]>> {
const response = await apiBack.post('qualis/conferences/refresh');
return response;
}

static async refreshJournals(): Promise<AxiosResponse<JournalQualis[]>> {
const response = await apiBack.post('qualis/journals/refresh');
return response;
}
}