Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Voland91 committed Mar 29, 2022
2 parents 18b096e + 4884787 commit 9f6bd55
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 11 deletions.
35 changes: 35 additions & 0 deletions src/api/issues/mockIssuesStatusAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { mockStatus } from "../../mockData/mockBoardStatus";
import { mockIssues } from "../../mockData/mockIssues";

function sleep(ms = 1000) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

const MockIssuesStatusAPI = {
getIssueStatusById: async function (IssueStatusId: any) {
await sleep();

const IssueStatusFilteredById = mockIssues.filter((el) => {
return el.id == IssueStatusId;
});

const issueString = mockStatus.data.filter((el) => {
return el.id == IssueStatusFilteredById[0].statusId;
});

return issueString[0].code;
},
getStatuses: async function () {
await sleep();

const issueStatusInString = mockStatus.data.map((el) => {
return el.code;
});

return [...issueStatusInString];
},
};

export default MockIssuesStatusAPI;
11 changes: 11 additions & 0 deletions src/mockData/mockIssues.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
export interface IssueType {
alias: string;
name: string;
description: string;
projectId: number;
boardId: number;
statusId: number;
id: number;
isActive: boolean;
}

export const mockIssues = [
{
alias: "mock issue 1",
Expand Down
79 changes: 69 additions & 10 deletions src/views/IssueDetails/IssueDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
TextOutlined,
} from "./IssueDetails.style";
import { useParams } from "react-router-dom";

import makeRequest from "../../api/makeFetchRequest";

import MockIssuesStatusAPI from "../../api/issues/mockIssuesStatusAPI";
import { API_ISSUE } from "../../api/contsans";

let FetchDataAPI: any;
Expand All @@ -24,7 +28,6 @@ async function importApiModule() {
if (localStorage["USE_MOCK"] === "true") {
const module = await import("../../api/issue/mockIssueDetails");
FetchDataAPI = module.default;
console.log(FetchDataAPI);
} else {
const module = await import("../../api/requestsApi");
FetchDataAPI = module.default;
Expand All @@ -34,20 +37,43 @@ async function importApiModule() {
export const IssueDetails = () => {
const { t } = useTranslation();

const issueStatus = [t("ToDo"), t("InProgress"), t("Done")];
const [status, setStatus] = useState<string>(t("ToDo"));

const { issueId, projectName } = useParams();
const [issueTitle, setIssueTitle] = useState("");
const [issueDescription, setIssueDescription] = useState("");
const [assigneeName, setAssigneeName] = useState("");
const reporterName = "Joe Doe";
const linkedIssues = "Apples & Oranges";
const [state, setState] = useState({});

function handleSelect(e: any) {
setStatus(e.target.value);
}
const [currentStatus, setCurrentStatus] = useState<string>("");
const [statusesApi, setStatusesApi] = useState<any[]>([]);
const [statuses, setStatuses] = useState<string[]>([]);

const { boardId, issueId, projectName } = useParams();

const handleSelect = async (e: any) => {
if (localStorage["USE_MOCK"] === "false") {
const newStatusId = statusesApi.filter(
(el) => el.iStatus === e.target.value
);

const patchData = async () => {
const body = {
statusId: {
data: newStatusId[0].statusId,
},
};
const response = await makeRequest(
`https://patronageapi.herokuapp.com/api/issue/${issueId}`,
"PATCH",
body
);
const addedData = await response.json();
return addedData;
};
await patchData();
}
setCurrentStatus(e.target.value);
};

const fetchIssueDetails = useCallback(async () => {
await importApiModule();
Expand All @@ -58,7 +84,40 @@ export const IssueDetails = () => {
});
}, []);

const fetchStatus = async () => {
if (localStorage["USE_MOCK"] === "true") {
const issueStatus = await MockIssuesStatusAPI.getIssueStatusById(issueId);

setCurrentStatus(issueStatus);
const availableStatuses = await MockIssuesStatusAPI.getStatuses();
setStatuses(availableStatuses);
return;
}
await importApiModule();
const boardStatus = await FetchDataAPI.getBoardStatusById(boardId);
const statusesFromApi = boardStatus[0].map((el: any) => ({
statusId: el.statusId,
iStatus: el.status.code,
}));

setStatusesApi(statusesFromApi);

const statusesInString = statusesFromApi.map((el: any) => el.iStatus);
setStatuses(statusesInString);

const issueStatusId = await FetchDataAPI.getData(
`https://patronageapi.herokuapp.com/api/issue/${issueId}`
);

const issueStatusString = await FetchDataAPI.getData(
`https://patronageapi.herokuapp.com/api/status/id?id=${issueStatusId.data.statusId}`
);

setCurrentStatus(issueStatusString.data.code);
};

useEffect(() => {
fetchStatus();
fetchIssueDetails();
return () => {
setState({});
Expand All @@ -72,8 +131,8 @@ export const IssueDetails = () => {
pageTitle={issueTitle}
interactiveElement={
<Select
options={issueStatus}
value={status}
options={statuses}
value={currentStatus}
handleSelect={handleSelect}
/>
}
Expand Down
3 changes: 2 additions & 1 deletion src/views/Projects/Projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ export const Projects = () => {
await importApiModule();
await FetchDataAPI.getData(API_GET_PROJECTS_LIST).then((res: any) => {
if (localStorage["USE_MOCK"] === "true") {
console.log(res.data);
setUseMock(true);
setProjects(res);
setProjects(res.data);
} else {
setProjects(res.data);
}
Expand Down

0 comments on commit 9f6bd55

Please sign in to comment.