Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Kta 60 results after uploading data #10

Merged
merged 53 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
964543c
Adding Loading spinner component
sandoche Oct 6, 2022
d96e8f6
New result page created
sandoche Oct 6, 2022
3921de9
Adding applicantId to the cookies
sandoche Oct 6, 2022
de58137
Adding redirection to result
sandoche Oct 6, 2022
5ba7607
Implementing style box of result
sandoche Oct 6, 2022
70f9e02
Loading block added
sandoche Oct 6, 2022
37f3da5
Creating dummy endpoint
sandoche Oct 6, 2022
6927c18
Improving types
sandoche Oct 6, 2022
16d396f
Polling logic implemented
sandoche Oct 6, 2022
9cf1099
Improve readability
sandoche Oct 6, 2022
0c1bd4f
Handling the results
sandoche Oct 6, 2022
50479d6
Removing test console.log
sandoche Oct 6, 2022
8c4bf61
Implementing logic to display results
sandoche Oct 6, 2022
38ad8b7
Success component implemented
sandoche Oct 6, 2022
52f64d0
Changing text
sandoche Oct 6, 2022
e98e5df
Adding try again button
sandoche Oct 6, 2022
e90e078
Improving button style
sandoche Oct 6, 2022
417f2e3
Handling long loadings
sandoche Oct 6, 2022
27343a4
Code is handling all the type of errors
sandoche Oct 6, 2022
9c01863
Refactoring button
sandoche Oct 6, 2022
ec5abc2
Renaming constant
sandoche Oct 6, 2022
e58f818
Adding user data in cookies
sandoche Oct 6, 2022
09eee96
Adding data to localstorage instead of cookies
sandoche Oct 6, 2022
ce892df
Retry feature implemented, UX needs to be improved
sandoche Oct 6, 2022
be81221
Adding a comment to the code
sandoche Oct 7, 2022
2e4e7cd
Improving error management
sandoche Oct 7, 2022
f4d72e7
Adding setting to remove refetch
sandoche Oct 7, 2022
f77e45b
Reorganizing components in folders
sandoche Oct 7, 2022
2cbbe4f
Fixing renaming of components
sandoche Oct 7, 2022
dd15f99
Refactoring and creating a card component
sandoche Oct 7, 2022
5622d4f
Refactoring the components for results
sandoche Oct 7, 2022
6d0d0c6
Refactoring the loading component
sandoche Oct 7, 2022
49526f9
Improve retry action
sandoche Oct 7, 2022
b0af28f
Fixing issue with bad importation
sandoche Oct 7, 2022
3990e21
Fixing bad importation
sandoche Oct 7, 2022
7fe73d3
Refactored the results success
sandoche Oct 7, 2022
ca89fda
Refactored the results failure page
sandoche Oct 7, 2022
43d54ba
Refactoring the api calls
sandoche Oct 7, 2022
5189393
Refactoring api calls and moving them to a service
sandoche Oct 7, 2022
57a6198
Adding loading animation and disabled fields while sending
sandoche Oct 7, 2022
a100775
Improving style
sandoche Oct 7, 2022
b194efe
Fixing mobile responsive
sandoche Oct 7, 2022
0d87e75
Improving style of landing page
sandoche Oct 7, 2022
8fc0bcd
Updating first error page
sandoche Oct 7, 2022
c44fa7c
Updated design to have the full flow more consistent
sandoche Oct 7, 2022
1415084
Changing failure text to make it more clear
sandoche Oct 10, 2022
88a07da
Results error text improved
sandoche Oct 10, 2022
0287365
Rephrasing the text
sandoche Oct 10, 2022
2f4ed1d
Rewriting positive message
sandoche Oct 10, 2022
9b5cec9
Reformatting values and adding comments for the constants
sandoche Oct 10, 2022
203e88d
Adding better error handling, linting rule of no magic number, and fi…
sandoche Oct 10, 2022
ff92a74
Renaming e to event
sandoche Oct 10, 2022
ee5c509
Adding missing status for loading state
sandoche Oct 10, 2022
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: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module.exports = {
'react/jsx-props-no-spreading': 'off',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'no-magic-numbers': 'error',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
reportUnusedDisableDirectives: true, // https://eslint.org/docs/user-guide/configuring#report-unused-eslint-disable-comments
settings: {
Expand Down
2 changes: 1 addition & 1 deletion constants/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const COOKIES_EXPIRATION_TIME = 60 * 60 * 24 * 30; // 30 days
export const COOKIES_EXPIRATION_TIME = 2592000; // 30 days
export const COOKIE_CHECK_ID_NAME = 'onfido-check-id';
export const LOCALSTORAGE_USER_DATA_NAME = 'onfido-user-data';
export const SHORT_POLLING_INTERVAL = 1000; // 1 second - Short polling applies when the check is in progress
Expand Down
4 changes: 3 additions & 1 deletion pages/[key]/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { fetchCheckResults } from '../../services/apiService';
import { CheckResultsStatus } from '../../types/CheckResults';

const ResultsPage: NextPage = () => {
const NO_POLLING = 0;

const [refetchInterval, setRefetchInterval] = useState(SHORT_POLLING_INTERVAL);
const setLongPolling = () => setRefetchInterval(LONG_POLLING_INTERVAL);
const stopPolling = () => setRefetchInterval(0);
const stopPolling = () => setRefetchInterval(NO_POLLING);

const { isLoading, error, data } = useQuery(['checkResults'], fetchCheckResults, {
refetchInterval,
Expand Down
5 changes: 3 additions & 2 deletions pages/api/check-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { COOKIE_CHECK_ID_NAME } from '../../constants';
import getOnfido from '../../helpers/onfido';
import type { CheckResults } from '../../types/CheckResults';
import { CheckResultsStatus } from '../../types/CheckResults';
import { NOT_FOUND, SUCCESS } from '../../utils/statusCodes';

const endpointName = 'check-results';

Expand All @@ -17,7 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const check = await onfido.check.find(checkId);

if (!checkId || !check) {
res.status(404).json({ isClear: null, status: CheckResultsStatus.notFound });
res.status(NOT_FOUND).json({ isClear: null, status: CheckResultsStatus.notFound });
return;
}

Expand All @@ -33,7 +34,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
]);

// This need to be updated / improved depending on the answer from the support
res.status(200).json({
res.status(SUCCESS).json({
isClear: check.result === null ? null : check.result === 'clear',
status: simplifiedStatus.get(check.status) ?? CheckResultsStatus.finished,
});
Expand Down
5 changes: 3 additions & 2 deletions pages/api/create-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import { COOKIE_CHECK_ID_NAME, COOKIES_EXPIRATION_TIME } from '../../constants';
import getOnfido from '../../helpers/onfido';
import type ApplicantTokenPair from '../../types/ApplicantTokenPair';
import { SERVER_ERROR, SUCCESS } from '../../utils/statusCodes';

const reportNames = [
'document',
Expand Down Expand Up @@ -40,7 +41,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
res.setHeader('Set-Cookie', `${COOKIE_CHECK_ID_NAME}=${check.id}; Max-Age=${COOKIES_EXPIRATION_TIME}; Path=/`);

console.log('Returning result', endpointName);
res.status(200).json(check);
res.status(SUCCESS).json(check);
} catch (error: unknown | OnfidoApiError) {
if (error instanceof OnfidoApiError) {
// An error response was received from the Onfido API, extra info is available.
Expand All @@ -51,6 +52,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
// No response was received for some reason e.g. a network error.
console.error({ error });
}
res.status(500).json(error);
res.status(SERVER_ERROR).json(error);
}
}
41 changes: 28 additions & 13 deletions pages/api/generate-token.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { OnfidoApiError } from '@onfido/api';
import type { NextApiRequest, NextApiResponse } from 'next';

import getOnfido from '../../helpers/onfido';
import type ApplicantTokenPair from '../../types/ApplicantTokenPair';
import { SERVER_ERROR, SUCCESS } from '../../utils/statusCodes';

const endpointName = 'generate-token';

const onfido = getOnfido();

export default async function handler(req: NextApiRequest, res: NextApiResponse<ApplicantTokenPair>) {
const applicantProperties = req.body; // https://documentation.onfido.com/#applicant-object
console.log('Starting', endpointName);
const applicant = await onfido.applicant.create(applicantProperties);
export default async function handler(req: NextApiRequest, res: NextApiResponse<ApplicantTokenPair | unknown>) {
try {
const applicantProperties = req.body; // https://documentation.onfido.com/#applicant-object
console.log('Starting', endpointName);
const applicant = await onfido.applicant.create(applicantProperties);

console.log('Applicant created', endpointName);
console.log('Applicant created', endpointName);

const sdkToken = await onfido.sdkToken.generate({
applicantId: applicant.id,
// referrer: 'http://localhost/**'
// crossDeviceUrl: "https://example.com"
});
const result = { applicantId: applicant.id, sdkToken };
const sdkToken = await onfido.sdkToken.generate({
applicantId: applicant.id,
// referrer: 'http://localhost/**'
// crossDeviceUrl: "https://example.com"
});
const result = { applicantId: applicant.id, sdkToken };

console.log('Returning result', endpointName);
res.status(200).json(result);
console.log('Returning result', endpointName);
res.status(SUCCESS).json(result);
} catch (error: unknown | OnfidoApiError) {
if (error instanceof OnfidoApiError) {
// An error response was received from the Onfido API, extra info is available.
console.error(error.message);
console.error(error.type);
console.error(error.isClientError());
} else {
// No response was received for some reason e.g. a network error.
console.error({ error });
}
res.status(SERVER_ERROR).json(error);
}
}
3 changes: 3 additions & 0 deletions utils/statusCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const SUCCESS = 200;
export const NOT_FOUND = 404;
export const SERVER_ERROR = 500;