Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make mock fake failed only once
Browse files Browse the repository at this point in the history
hervedombya committed Nov 6, 2023
1 parent 9cfc29a commit 2eba140
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/react/ui-elements/Veeam/useMockData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useState } from 'react';
import { usePrevious } from '../../utils/hooks';

type MockTableData = {
action: string;
@@ -50,12 +49,12 @@ export const useMockData = ({
setId: (id: number) => void;
}) => {
const [data, setData] = useState<MockTableData[]>(mockTableData);
const [isError, setIsError] = useState<boolean>(false);
const randomIndex = Math.floor(Math.random() * status.length);
const previousIndex = usePrevious(randomIndex);

const fetchMockData = async () => {
const response = await Promise.resolve(
status[previousIndex === 1 ? 0 : randomIndex],
status[randomIndex === 1 && isError ? 0 : randomIndex],
);
const newData = data.map((item) => {
if (item.action === data[id].action) {
@@ -76,5 +75,11 @@ export const useMockData = ({
}
}, [id]);

useEffect(() => {
if (randomIndex === 1) {
setIsError(true);
}
}, [randomIndex]);

return { data };
};

0 comments on commit 2eba140

Please sign in to comment.