Skip to content

Commit

Permalink
eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnau Zapata Delgado authored and Arnau Zapata Delgado committed Jul 13, 2023
1 parent df293ed commit 43f0bf9
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 143 deletions.
25 changes: 0 additions & 25 deletions src/pages/api/verify-file.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ErrorPage = () => {
return (
<>
{line}
{index != phrase.length - 1 && <br />}
{index !== phrase.length - 1 && <br />}
</>
)
})
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const FileVerification: NextPage<{}> = () => {
try {
const { error, message, hash, url, timestamp }: any =
await ApiClient.verifyFile(uploadedFile)
if (message == 'OK') {
if (message === 'OK') {
router.push(`/success?timestamp=${timestamp}&url=${url}&hash=${hash}`, '/success')
} else {
router.push('/error?error=' + error)
Expand Down
140 changes: 68 additions & 72 deletions src/pages/validateQR/index.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,64 @@
/* eslint-disable camelcase */
import React, { useEffect, useState } from 'react'
import { NextPage } from 'next'
import { useRouter } from 'next/router'
import { Button, Upload, Layout, Col, Row } from 'antd'
import { UploadOutlined } from '@ant-design/icons'
import styled from 'styled-components'
import React, { useEffect, useState } from 'react';
import { NextPage } from 'next';
import { useRouter } from 'next/router';
import { Button, Col, Row } from 'antd';
import { NotificationContainer, NotificationManager } from 'react-notifications';

import ApiClient from '../../services/ApiClient'
import Loader from '../../components/Loader'
import Paragraph from '../../components/Paragraph'
import ApiClient from '../../services/ApiClient';
import Loader from '../../components/Loader';
import Paragraph from '../../components/Paragraph';
import {
InversePrimaryButton,
PrimaryButton
} from '../../components/PrimaryButton'
import { NotificationContainer, NotificationManager } from 'react-notifications'
import 'react-notifications/lib/notifications.css'
} from '../../components/PrimaryButton';
import 'react-notifications/lib/notifications.css';
import {
IndexContainer,
IndexTitle,
IndexParagraph,
IndexSendContainer
} from './style'
} from './style';

const ValidateQR: NextPage<{}> = () => {
const [uploadedFile, setUploadedFile] = useState<File>()
const [isProcessingRequest, setIsProcessingRequest] = useState(false)
const router = useRouter()
const uuid = router.query.id as string
const [uploadedFile, setUploadedFile] = useState<File>();
const [isProcessingRequest, setIsProcessingRequest] = useState(false);
const router = useRouter();
const uuid = router.query.id as string;

useEffect(() => {
try {
getFileFromUuid(uuid)
getFileFromUuid(uuid);
} catch (error) {
// console.log('error', error)
}
}, [uuid])
}, [uuid]);

const getFileFromUuid = async (uuid: string, isDownload?: boolean) => {
try {
let ipfsURL
let ipfsURL;

if (uploadedFile) {
if (isDownload) {
const fileName = `${uuid || 'file'}.pdf`
const link = document.createElement('a')
link.href = window.URL.createObjectURL(uploadedFile)
link.download = fileName
link.click()
const fileName = `${uuid || 'file'}.pdf`;
const link = document.createElement('a');
link.href = window.URL.createObjectURL(uploadedFile);
link.download = fileName;
link.click();
}
return { file: uploadedFile }
return { file: uploadedFile };
} else if (uuid) {
const response: any = await ApiClient.getIPSFFromUuid(uuid)
const ipfsStatus = response?.status
const ipfsError = response?.error
const ipfsMessage = response?.message
ipfsURL = response?.ipfsURL
if (ipfsStatus != 404 && ipfsMessage === 'OK') {
const file: any = await ApiClient.generateFile(
ipfsURL,
uuid,
isDownload
)
setUploadedFile(file)
return { file }
} else return { file: null, ipfsError }
const response: any = await ApiClient.getIPSFFromUuid(uuid);
const ipfsStatus = response?.status;
const ipfsError = response?.error;
const ipfsMessage = response?.message;
ipfsURL = response?.ipfsURL;

if (ipfsStatus !== 404 && ipfsMessage === 'OK') {
const file: any = await ApiClient.generateFile(ipfsURL, uuid, isDownload);
setUploadedFile(file);
return { file };
} else return { file: null, ipfsError };
}
} catch (error) {
if (isDownload) {
Expand All @@ -70,46 +67,49 @@ const ValidateQR: NextPage<{}> = () => {
'',
5000,
() => {
alert('callback')
alert('callback');
}
)
);
} else {
throw error
throw error;
}
}
}
};

const sendIdentifier = async (uuid) => {
try {
if (uuid) {
setIsProcessingRequest(true)
const { file, ipfsError } = await getFileFromUuid(uuid)
setIsProcessingRequest(true);
const { file, ipfsError } = await getFileFromUuid(uuid);

if (ipfsError) {
const errorCode = ApiClient.getErrorCode(ipfsError)
router.push(`/error?error=${errorCode}`)
return
const errorCode = ApiClient.getErrorCode(ipfsError);
router.push(`/error?error=${errorCode}`);
return;
}
const responseVerifyFile: any = await ApiClient.verifyFile(file)
const { error, message, hash, url, timestamp }: any = responseVerifyFile
if (message == 'OK') {

const responseVerifyFile: any = await ApiClient.verifyFile(file);
const { error, message, hash, url, timestamp }: any = responseVerifyFile;

if (message === 'OK') {
router.push(
`/success?timestamp=${timestamp}&url=${url}&hash=${hash}`,
'/success'
)
);
} else {
const errorCode = ApiClient.getErrorCode(error)
router.push(`/error?error=${errorCode}`)
const errorCode = ApiClient.getErrorCode(error);
router.push(`/error?error=${errorCode}`);
}
}
} catch (error) {
const errorCode = ApiClient.getErrorCode(error)
router.push(`/error?error=${errorCode}`)
const errorCode = ApiClient.getErrorCode(error);
router.push(`/error?error=${errorCode}`);
}
}
};

const renderLoadingView = () => {
return <Loader />
}
return <Loader />;
};

const renderUploadFileView = () => {
return (
Expand All @@ -121,8 +121,7 @@ const ValidateQR: NextPage<{}> = () => {
xl={{ span: 14, push: 3 }}
>
<IndexTitle data-cy="title">
Te damos la bienvenida al Servicio de Verificación de documentos
en blockchain
Te damos la bienvenida al Servicio de Verificación de documentos en blockchain
</IndexTitle>
</Col>
</Row>
Expand All @@ -134,12 +133,9 @@ const ValidateQR: NextPage<{}> = () => {
>
<Paragraph>
<IndexParagraph data-cy="first-paragraph">
Izertis te permite contrastar cualquier documento notarizado en
blockchain en la Red T de Alastria.
Izertis te permite contrastar cualquier documento notarizado en blockchain en la Red T de Alastria.
<br />
Para verificar el documento del que has escaneado el QR, debes
pulsar el botón VERIFICAR. Si lo deseas, puedes descargarte una
copia del mismo en el botón DESCARGAR.
Para verificar el documento del que has escaneado el QR, debes pulsar el botón VERIFICAR. Si lo deseas, puedes descargarte una copia del mismo en el botón DESCARGAR.
</IndexParagraph>
</Paragraph>
</Col>
Expand Down Expand Up @@ -191,10 +187,10 @@ const ValidateQR: NextPage<{}> = () => {
</Row>
<NotificationContainer />
</IndexContainer>
)
}
);
};

return isProcessingRequest ? renderLoadingView() : renderUploadFileView()
}
return isProcessingRequest ? renderLoadingView() : renderUploadFileView();
};

export default ValidateQR
export default ValidateQR;
1 change: 1 addition & 0 deletions src/pages/validateQR/style.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Layout, Upload } from "antd"
import styled from "styled-components"

import { DescriptionText, PageTitle } from "../../components/atomic_components/Text/variants"
import { backgroundGray, black } from "../../theme/color"
import media from '../../theme/media'
Expand Down
Loading

0 comments on commit 43f0bf9

Please sign in to comment.