Skip to content

Commit

Permalink
Merge pull request #46 from AplinkosMinisterija/44-praleisti-prettier…
Browse files Browse the repository at this point in the history
…-globaliai-ir-sutvarkyti-lint-errorus

44 praleisti prettier globaliai ir sutvarkyti lint errorus
  • Loading branch information
DovMa authored Jan 23, 2024
2 parents 9a22e15 + 951d152 commit 39a6f6d
Show file tree
Hide file tree
Showing 90 changed files with 1,294 additions and 1,870 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Continuous integration

on:
push:
branches: [ main ]
branches: [main]
pull_request:

jobs:
Expand Down Expand Up @@ -39,4 +39,4 @@ jobs:
uses: AplinkosMinisterija/reusable-workflows/.github/actions/docker-build-tag-push@main
with:
environment: test
push: false
push: false
2 changes: 1 addition & 1 deletion .github/workflows/deploy-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
build-args: |
NODE_ENV=development
VITE_SENTRY_DSN=https://0385edf7f78f4ad4a511abae516ae3e8@sentry.biip.lt/7
VITE_MAPS_HOST=https://dev.maps.biip.lt
VITE_MAPS_HOST=https://dev.maps.biip.lt
2 changes: 1 addition & 1 deletion .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
build-args: |
NODE_ENV=production
VITE_SENTRY_DSN=https://0385edf7f78f4ad4a511abae516ae3e8@sentry.biip.lt/7
VITE_MAPS_HOST=https://maps.biip.lt
VITE_MAPS_HOST=https://maps.biip.lt
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy to Staging

on:
push:
branches: [ main ]
branches: [main]

jobs:
deploy-staging:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecards-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
# Weekly on Saturdays.
- cron: '30 1 * * 6'
push:
branches: [ main ]
branches: [main]
workflow_dispatch:

# Declare default permissions as read only.
Expand Down Expand Up @@ -37,4 +37,4 @@ jobs:
- name: Upload SARIF results to code scanning
uses: github/codeql-action/upload-sarif@83f0fe6c4988d98a455712a27f0255212bba9bd4 # v2.3.6
with:
sarif_file: results.sarif
sarif_file: results.sarif
48 changes: 24 additions & 24 deletions manifest.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
export const manifestForPlugIn = {
registerType: "prompt",
includeAssests: ["favicon.ico", "apple-touc-icon.png", "masked-icon.svg"],
registerType: 'prompt',
includeAssests: ['favicon.ico', 'apple-touc-icon.png', 'masked-icon.svg'],
manifest: {
short_name: "Įžuvinimas",
name: "BĮIP Įžuvinimas",
short_name: 'Įžuvinimas',
name: 'BĮIP Įžuvinimas',
icons: [
{
src: "b-icon.png",
sizes: "64x64 32x32 24x24 16x16",
type: "image/png"
src: 'b-icon.png',
sizes: '64x64 32x32 24x24 16x16',
type: 'image/png',
},
{
src: "b-icon.png",
type: "image/png",
sizes: "192x192"
src: 'b-icon.png',
type: 'image/png',
sizes: '192x192',
},
{
src: "b-icon.png",
type: "image/png",
sizes: "512x512"
}
src: 'b-icon.png',
type: 'image/png',
sizes: '512x512',
},
],
theme_color: "#171717",
background_color: "#0a1353",
display: "standalone",
scope: "/",
start_url: "/",
orientation: "portrait"
theme_color: '#171717',
background_color: '#0a1353',
display: 'standalone',
scope: '/',
start_url: '/',
orientation: 'portrait',
},
workbox: {
runtimeCaching: [
{
urlPattern: /\.(png|jpg|jpeg|svg|gif)$/,
handler: "CacheFirst"
}
]
}
handler: 'CacheFirst',
},
],
},
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"prettier --write"
"prettier --write",
"eslint"
],
"*.{md,html,css}": "prettier --write"
}
Expand Down
133 changes: 46 additions & 87 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isEqual } from "lodash";
import { useCallback, useEffect, useRef, useState } from "react";
import { useMutation } from "react-query";
import { isEqual } from 'lodash';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useMutation } from 'react-query';
import {
Location,
Navigate,
Expand All @@ -9,25 +9,21 @@ import {
Routes,
useLocation,
useNavigate,
useSearchParams
} from "react-router-dom";
import { ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import Cookies from "universal-cookie";
import LoaderComponent from "./components/other/LoaderComponent";
import { CantLogin } from "./pages/CantLogin";
import { Login } from "./pages/Login";
import { useAppSelector } from "./state/hooks";
import api from "./utils/api";
import { ServerErrorCodes } from "./utils/constants";
import { handleUpdateTokens } from "./utils/functions";
import {
useCheckAuthMutation,
useEGatesSign,
useFilteredRoutes
} from "./utils/hooks";
import { slugs } from "./utils/routes";
import { ProfileId } from "./utils/types";
useSearchParams,
} from 'react-router-dom';
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import Cookies from 'universal-cookie';
import LoaderComponent from './components/other/LoaderComponent';
import { CantLogin } from './pages/CantLogin';
import { Login } from './pages/Login';
import { useAppSelector } from './state/hooks';
import api from './utils/api';
import { ServerErrorCodes } from './utils/constants';
import { handleUpdateTokens } from './utils/functions';
import { useCheckAuthMutation, useEGatesSign, useFilteredRoutes } from './utils/hooks';
import { slugs } from './utils/routes';
import { ProfileId } from './utils/types';
const cookies = new Cookies();
interface RouteProps {
loggedIn: boolean;
Expand All @@ -40,63 +36,55 @@ function App() {
const profiles = useAppSelector((state) => state.user.userData.profiles);
const [searchParams] = useSearchParams();
const { ticket, eGates } = Object.fromEntries([...Array.from(searchParams)]);
const profileId: ProfileId = cookies.get("profileId");
const profileId: ProfileId = cookies.get('profileId');
const [initialLoading, setInitialLoading] = useState(true);
const location = useLocation();
const navigate = useNavigate();
const routes = useFilteredRoutes();
const navigateRef = useRef(navigate);

const isInvalidProfile =
!profiles?.map((profile) => profile?.id?.toString()).includes(profileId) &&
loggedIn;
!profiles?.map((profile) => profile?.id?.toString()).includes(profileId) && loggedIn;

const updateTokensMutation = useMutation(api.refreshToken, {
onError: ({ response }: any) => {
if (isEqual(response.status, ServerErrorCodes.NOT_FOUND)) {
cookies.remove("refreshToken", { path: "/" });
cookies.remove('refreshToken', { path: '/' });
}
},
onSuccess: (data) => {
handleUpdateTokens(data);
}
},
});

const updateTokensMutationMutateAsyncFunction =
updateTokensMutation.mutateAsync;
const updateTokensMutationMutateAsyncFunction = updateTokensMutation.mutateAsync;

const shouldUpdateTokens = useCallback(async () => {
if (!cookies.get("token") && cookies.get("refreshToken")) {
if (!cookies.get('token') && cookies.get('refreshToken')) {
await updateTokensMutationMutateAsyncFunction();
}
}, [updateTokensMutationMutateAsyncFunction]);

const { mutateAsync: eGateSignsMutation, isLoading: eGatesSignLoading } =
useEGatesSign();
const { mutateAsync: eGateSignsMutation, isLoading: eGatesSignLoading } = useEGatesSign();

const { mutateAsync: checkAuthMutation } = useCheckAuthMutation();

const eGatesLoginMutation = useMutation(
(ticket: string) => api.eGatesLogin({ ticket }),
{
onError: () => {
navigate(slugs.cantLogin);
},
onSuccess: (data) => {
handleUpdateTokens(data);
checkAuthMutation();
},
retry: false
}
);
const eGatesLoginMutation = useMutation((ticket: string) => api.eGatesLogin({ ticket }), {
onError: () => {
navigate(slugs.cantLogin);
},
onSuccess: (data) => {
handleUpdateTokens(data);
checkAuthMutation();
},
retry: false,
});

const isLoading =
initialLoading ||
[
eGatesLoginMutation.isLoading,
eGatesSignLoading,
updateTokensMutation.isLoading
].some((loading) => loading);
[eGatesLoginMutation.isLoading, eGatesSignLoading, updateTokensMutation.isLoading].some(
(loading) => loading,
);

useEffect(() => {
(async () => {
Expand All @@ -119,22 +107,16 @@ function App() {
eGateSignsMutation();
}
})();
}, [
ticket,
eGates,
eGateSignsMutation,
eGatesLoginMutationMutateAsync,
loggedIn
]);
}, [ticket, eGates, eGateSignsMutation, eGatesLoginMutationMutateAsync, loggedIn]);

useEffect(() => {
if (!isInvalidProfile) return;

cookies.remove("profileId", { path: "/" });
cookies.remove('profileId', { path: '/' });

if (!navigateRef?.current) return;

navigateRef?.current("");
navigateRef?.current('');
}, [profileId, loggedIn, isInvalidProfile]);

if (isLoading) {
Expand All @@ -144,41 +126,23 @@ function App() {
return (
<>
<Routes>
<Route
element={<PublicRoute profileId={profileId} loggedIn={loggedIn} />}
>
<Route element={<PublicRoute profileId={profileId} loggedIn={loggedIn} />}>
<Route path={slugs.login} element={<Login />} />
<Route path={slugs.cantLogin} element={<CantLogin />} />
</Route>

<Route
element={
<ProtectedRoute
location={location}
profileId={profileId}
loggedIn={loggedIn}
/>
}
element={<ProtectedRoute location={location} profileId={profileId} loggedIn={loggedIn} />}
>
{(routes || []).map((route, index) => (
<Route
key={`route-${index}`}
path={route.slug}
element={route.component}
/>
<Route key={`route-${index}`} path={route.slug} element={route.component} />
))}
</Route>
<Route
path="*"
element={
<Navigate
to={
loggedIn
? profileId
? slugs.fishStockings
: slugs.profiles
: slugs.login
}
to={loggedIn ? (profileId ? slugs.fishStockings : slugs.profiles) : slugs.login}
/>
}
/>
Expand All @@ -190,12 +154,7 @@ function App() {

const PublicRoute = ({ loggedIn, profileId }: RouteProps) => {
if (loggedIn) {
return (
<Navigate
to={!!profileId ? slugs.fishStockings : slugs.profiles}
replace
/>
);
return <Navigate to={profileId ? slugs.fishStockings : slugs.profiles} replace />;
}

return <Outlet />;
Expand Down
16 changes: 6 additions & 10 deletions src/components/Layouts/Default.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import Div100vh from "react-div-100vh";
import styled from "styled-components";
import InstallButton from "../other/InstallButton";
import NavBar from "../other/Navbar";
import PWAInstallerPrompt from "../other/PWAInstallerPrompt";
import Div100vh from 'react-div-100vh';
import styled from 'styled-components';
import InstallButton from '../other/InstallButton';
import NavBar from '../other/Navbar';
import PWAInstallerPrompt from '../other/PWAInstallerPrompt';

export interface DefaultLayoutProps {
children?: React.ReactNode;
maxWidth?: string;
onScroll?: any;
}

const DefaultLayout = ({
children,
maxWidth = "100%",
onScroll
}: DefaultLayoutProps) => {
const DefaultLayout = ({ children, maxWidth = '100%', onScroll }: DefaultLayoutProps) => {
return (
<Div100vh>
<Container>
Expand Down
Loading

0 comments on commit 39a6f6d

Please sign in to comment.