Skip to content

Commit

Permalink
Merge pull request #43 from fga-eps-mds/fix-sonar-hotspots
Browse files Browse the repository at this point in the history
fix(#149): adding fix to reability and manutenability
  • Loading branch information
DaviMatheus authored Sep 9, 2024
2 parents b937e41 + d4623ea commit 84c1514
Show file tree
Hide file tree
Showing 46 changed files with 428 additions and 442 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
29 changes: 5 additions & 24 deletions src/app/(auth)/oauth/page.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
'use client';

import { signIn, useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import { useSearchParams } from 'next/navigation';
import { Suspense } from 'react';
import { signIn } from 'next-auth/react';
import { useRouter, useSearchParams } from 'next/navigation';
import { useEffect, useState, Suspense } from 'react';
import { toast } from 'sonner';
import { useMutation } from '@tanstack/react-query';
import loadImage from '@/public/loading.gif';
import { CircularProgress } from '@mui/material';

const signInWithToken = async ({
token,
refresh,
}: {
token: string;
refresh: string;
}) => {
const result = await signIn('credentials', {
token,
refresh,
redirect: false,
});
};

const OAuthContent = () => {
const router = useRouter();
const { data: session } = useSession();
const [message, setMessage] = useState('Carregando...');
const searchParams = useSearchParams();
const token = searchParams.get('token');
const refresh = searchParams.get('refresh');
Expand All @@ -45,7 +26,7 @@ const OAuthContent = () => {
toast.error('Erro ao efetuar login, por favor tente novamente!');
router.push('/login');
}

setIsPending(false);
localStorage.setItem('token', JSON.stringify(token));
localStorage.setItem('refresh', JSON.stringify(refresh));
router.push('/home');
Expand All @@ -60,7 +41,7 @@ const OAuthContent = () => {

return (
<div className="flex justify-center items-center h-screen">
{isPending ? <CircularProgress /> : message}
{isPending ? <CircularProgress /> : 'Carregando...'}
</div>
);
};
Expand Down
3 changes: 1 addition & 2 deletions src/app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
DialogActions,
DialogContent,
DialogTitle,
Button,
Typography,
} from '@mui/material';

Expand Down Expand Up @@ -90,7 +89,7 @@ const Admin: React.FC = () => {
if (selectedUser && selectedRole) {
try {
const token = JSON.parse(localStorage.getItem('token')!);
await updateUserRole(selectedUser._id, selectedRole,token);
await updateUserRole(selectedUser._id, selectedRole, token);
const updatedUsers = users.map((user) =>
user._id === selectedUser._id
? { ...user, role: selectedRole }
Expand Down
8 changes: 4 additions & 4 deletions src/app/forgot-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Image from 'next/image';
import MyButton from '@/components/ui/buttons/myButton.component';
import { Box, TextField, Button } from '@mui/material';
import { Box, TextField } from '@mui/material';
import { useMutation } from '@tanstack/react-query';
import calcuclusLogo from '@/public/calculus-logo.svg';
import { forgotPassword } from '@/services/user.service';
Expand All @@ -25,15 +25,15 @@ export default function ForgotPassword() {
resolver: zodResolver(forgotPasswordSchema),
});

const { mutate, isPending } = useMutation({
const { mutate } = useMutation({
mutationFn: async (data: ForgotPasswordData) => await forgotPassword(data),
onSuccess: (data) => {
onSuccess: () => {
toast.success(
'Email enviado com sucesso! Verifique sua caixa de entrada para obter as instruções.',
);
router.push('/');
},
onError: (error) => {
onError: () => {
toast.error(
'Ocorreu um erro ao enviar o email. Tente novamente mais tarde.',
);
Expand Down
5 changes: 0 additions & 5 deletions src/app/home/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
'use client';

import { useSession } from 'next-auth/react';
import HomePrincipalPage from '@/components/home/homePage';

export default function HomePage() {
const { data: session } = useSession();

return (
<div className="bg-[#F1F1F1] min-h-screen">
<div className="bg-[#F1F1F1] max-w-7xl mx-auto pt-14 px-5">
Expand Down
127 changes: 75 additions & 52 deletions src/app/journey-page/[journeyId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
'use client';

import React, { useEffect, useState } from 'react';
import { Box, CircularProgress, Divider, IconButton, Typography } from '@mui/material';
import {
Box,
CircularProgress,
Divider,
IconButton,
Typography,
} from '@mui/material';
import JourneyInfo from '@/components/journey/journeyInfo';
import JourneyPath from '@/components/journey/journeyPath';
import { getJourney, getJourneysByPoint, getTrails } from '@/services/studioMaker.service';
import {
getJourney,
getJourneysByPoint,
getTrails,
} from '@/services/studioMaker.service';
import { Journey } from '@/lib/interfaces/journey.interface';
import { Trail } from '@/lib/interfaces/trails.interface';
import { useParams, useRouter } from 'next/navigation';
import { getSubscribedJourneys, } from '@/services/user.service';
import {
getSubscribedJourneys,
getCompletedTrails,
} from '@/services/user.service';
import { useSession } from 'next-auth/react';
import { getCompletedTrails } from '@/services/user.service';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';


export default function JourneyPage() {
const { journeyId } = useParams();
const router = useRouter();
Expand All @@ -33,9 +44,7 @@ export default function JourneyPage() {
try {
const completed = await getCompletedTrails(session.user.id);
setCompletedTrails(completed);
} catch (error) {
console.error('Error fetching completed trails:', error);
}
} catch (error) {}
}
};
fetchCompletedTrails();
Expand All @@ -56,13 +65,17 @@ export default function JourneyPage() {
const pointId = journeyData.point;
if (pointId) {
const relatedJourneys: Journey[] = await getJourneysByPoint(pointId);
const next = relatedJourneys.find(j => j.order === journeyData.order + 1);
const next = relatedJourneys.find(
(j) => j.order === journeyData.order + 1,
);
if (next != undefined) {
setNextJourney(next);
console.log(next);
console.log(nextJourney);
}
const previous = relatedJourneys.find(j => j.order === journeyData.order - 1);
const previous = relatedJourneys.find(
(j) => j.order === journeyData.order - 1,
);
if (previous != undefined) {
setPreviousJourney(previous);
console.log(previous);
Expand Down Expand Up @@ -90,11 +103,11 @@ export default function JourneyPage() {

const handleNext = async () => {
router.push(`/journey-page/${nextJourney?._id}`);
}
};

const handlePrevious = async () => {
router.push(`/journey-page/${previousJourney?._id}`);
}
};

if (error) {
return <div>{error}</div>;
Expand All @@ -109,45 +122,53 @@ export default function JourneyPage() {
);

return (
<Box sx={{
backgroundColor: '#f1f1f1',
height: '100vh',
position: 'relative',
}}>
{(previousJourney) &&
<IconButton onClick={handlePrevious} sx={{
position: 'absolute',
top: '10%',
left: '5%',
backgroundColor: '#FF4122',
height: '40px',
width: '40px',
borderRadius: '40px',
color: '#f1f1f1',
transform: 'translateY(-50%)',
zIndex: 2,
}}>
<Box
sx={{
backgroundColor: '#f1f1f1',
height: '100vh',
position: 'relative',
}}
>
{previousJourney && (
<IconButton
onClick={handlePrevious}
sx={{
position: 'absolute',
top: '10%',
left: '5%',
backgroundColor: '#FF4122',
height: '40px',
width: '40px',
borderRadius: '40px',
color: '#f1f1f1',
transform: 'translateY(-50%)',
zIndex: 2,
}}
>
<ArrowBackIcon />
</IconButton>
}

{(nextJourney) &&
<IconButton onClick={handleNext} sx={{
position: 'absolute',
top: '10%',
right: '5%',
backgroundColor: '#FF4122',
height: '40px',
width: '40px',
borderRadius: '40px',
color: '#f1f1f1',
transform: 'translateY(-50%)',
zIndex: 2,
}}>
)}

{nextJourney && (
<IconButton
onClick={handleNext}
sx={{
position: 'absolute',
top: '10%',
right: '5%',
backgroundColor: '#FF4122',
height: '40px',
width: '40px',
borderRadius: '40px',
color: '#f1f1f1',
transform: 'translateY(-50%)',
zIndex: 2,
}}
>
<ArrowForwardIcon />
</IconButton>
}
)}

<Box
sx={{
display: 'flex',
Expand All @@ -168,14 +189,14 @@ export default function JourneyPage() {
completedTrailsCount={completedTrailsInJourney.length}
/>
</Box>

<Divider
sx={{ marginBottom: '100px', marginTop: '100px' }}
orientation="vertical"
variant="middle"
flexItem
/>

{!trails.length ? (
<Typography
variant="h3"
Expand All @@ -188,9 +209,11 @@ export default function JourneyPage() {
Ainda não há trilhas nessa jornada
</Typography>
) : (
<React.Fragment>
<JourneyPath trails={trails} journeyId={journey._id} hasJourney={hasJourney} />
</React.Fragment>
<JourneyPath
trails={trails}
journeyId={journey._id}
hasJourney={hasJourney}
/>
)}
</Box>
</Box>
Expand Down
14 changes: 2 additions & 12 deletions src/app/journey/[...pointId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { toast } from 'sonner';
export default function JourneyPage({
params,
}: {
params: { pointId: string };
readonly params: { pointId: string };
}) {
const fetchJourneys = async (): Promise<Journey[]> => {
let journeys = await getJourneysByPoint(params.pointId);
Expand Down Expand Up @@ -85,8 +85,6 @@ export default function JourneyPage({

const handleJourneyAction = (action: string) => {
if (action === 'editar') setEditionDialogOpen(true);
if (action === 'gerenciar') {
}
if (action === 'excluir') setExclusionDialogOpen(true);
};

Expand Down Expand Up @@ -116,20 +114,12 @@ export default function JourneyPage({
}
};

const handleCloseCreateDialog = () => {
setCreateDialogOpen(false);
};

if (isLoading) {
return <CircularProgress />;
}

if (error) {
return (
<Typography>
Error fetching journeys: {(error as Error).message}
</Typography>
);
return <Typography>Error fetching journeys</Typography>;
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/app/register/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Box, Typography, IconButton, Link, Grid } from '@mui/material';
import { Box, Typography, Link, Grid } from '@mui/material';
import Image from 'next/image';
import maoCerebro from '@/public/mao_cerebro.png';
import { SingUpForm } from '@/components/forms/signUpForm';
Expand Down
Loading

0 comments on commit 84c1514

Please sign in to comment.