|
| 1 | +/** |
| 2 | + * Input Job Description page |
| 3 | + * |
| 4 | + */ |
| 5 | +import React, { useCallback, useEffect, useState } from "react"; |
| 6 | +import { useData } from "hooks/useData"; |
| 7 | +import { navigate } from "@reach/router"; |
| 8 | +import { toastr } from "react-redux-toastr"; |
| 9 | +import { setCurrentStage } from "utils/helpers"; |
| 10 | +import Page from "components/Page"; |
| 11 | +import PT from "prop-types"; |
| 12 | +import PageHeader from "components/PageHeader"; |
| 13 | +import LoadingIndicator from "components/LoadingIndicator"; |
| 14 | +import MarkdownEditor from "../../../../components/MarkdownEditor"; |
| 15 | +import { getSkillsByJobDescription } from "../../../../services/teams"; |
| 16 | +import Completeness from "../../components/Completeness"; |
| 17 | +import { getSkills } from "services/skills"; |
| 18 | +import SearchCard from "../../components/SearchCard"; |
| 19 | +import ResultCard from "../../components/ResultCard"; |
| 20 | +import AddAnotherModal from "../../components/AddAnotherModal"; |
| 21 | +import SkillListPopup from "./components/SkillListPopup"; |
| 22 | +import "./styles.module.scss"; |
| 23 | +import withAuthentication from "../../../../hoc/withAuthentication"; |
| 24 | +import IconOfficeFileText from "../../../../assets/images/icon-office-file-text.svg"; |
| 25 | + |
| 26 | +function InputJobDescription() { |
| 27 | + const [stages, setStages] = useState([ |
| 28 | + { name: "Input Job Desccription", isCurrent: true }, |
| 29 | + { name: "Search Member" }, |
| 30 | + { name: "Overview of the Results" }, |
| 31 | + ]); |
| 32 | + const [jdString, setJdString] = useState(""); |
| 33 | + const [searchState, setSearchState] = useState(null); |
| 34 | + const [modalOpen, setModalOpen] = useState(false); |
| 35 | + const [skillModalOpen, setSkillModalOpen] = useState(false); |
| 36 | + const [submitDone, setSubmitDone] = useState(false); |
| 37 | + const [skills, setSkills] = useState([]); |
| 38 | + const [isLoadingSkills, setIsLoadingSkills] = useState(false); |
| 39 | + |
| 40 | + const onSearch = useCallback( |
| 41 | + (value) => { |
| 42 | + setSkillModalOpen(true); |
| 43 | + setIsLoadingSkills(true); |
| 44 | + getSkillsByJobDescription(jdString) |
| 45 | + .then((response) => { |
| 46 | + setSkills(response.data); |
| 47 | + setIsLoadingSkills(false); |
| 48 | + setSkillModalOpen(true); |
| 49 | + }) |
| 50 | + .catch(() => { |
| 51 | + setIsLoadingSkills(false); |
| 52 | + }); |
| 53 | + }, |
| 54 | + [jdString] |
| 55 | + ); |
| 56 | + |
| 57 | + const onConfirationClick = useCallback(() => { |
| 58 | + setSearchState("searching"); |
| 59 | + setCurrentStage(1, stages, setStages); |
| 60 | + setTimeout(() => { |
| 61 | + setCurrentStage(2, stages, setStages); |
| 62 | + setSearchState("done"); |
| 63 | + }, 3000); |
| 64 | + }, []); |
| 65 | + |
| 66 | + const addAnother = useCallback(() => { |
| 67 | + // navigate(`/taas/myteams/createnewteam/${projectId}/role`); |
| 68 | + }, []); |
| 69 | + |
| 70 | + const submitJob = () => { |
| 71 | + setSubmitDone(false); |
| 72 | + setModalOpen(true); |
| 73 | + setTimeout(() => { |
| 74 | + setSubmitDone(true); |
| 75 | + }, 3000); |
| 76 | + }; |
| 77 | + |
| 78 | + const onEditChange = useCallback((value) => { |
| 79 | + setJdString(value); |
| 80 | + }, []); |
| 81 | + |
| 82 | + return ( |
| 83 | + <div> |
| 84 | + {!searchState ? ( |
| 85 | + <div styleName="page"> |
| 86 | + <div styleName="edit-container"> |
| 87 | + <PageHeader |
| 88 | + title="Input Job Description" |
| 89 | + backTo="/taas/myteams/createnewteam" |
| 90 | + /> |
| 91 | + <MarkdownEditor |
| 92 | + height="482px" |
| 93 | + placeholder="input job description" |
| 94 | + onChange={onEditChange} |
| 95 | + /> |
| 96 | + </div> |
| 97 | + <Completeness |
| 98 | + extraStyleName="input-job-description" |
| 99 | + isDisabled={jdString.length < 10} |
| 100 | + stages={stages} |
| 101 | + onClick={onSearch} |
| 102 | + buttonLabel="Search" |
| 103 | + percentage="26" |
| 104 | + /> |
| 105 | + <SkillListPopup |
| 106 | + open={skillModalOpen} |
| 107 | + skills={skills} |
| 108 | + onClose={() => setSkillModalOpen(false)} |
| 109 | + isLoading={isLoadingSkills} |
| 110 | + onContinueClick={onConfirationClick} |
| 111 | + /> |
| 112 | + </div> |
| 113 | + ) : searchState === "searching" ? ( |
| 114 | + <div styleName="page"> |
| 115 | + <SearchCard /> |
| 116 | + <Completeness |
| 117 | + extraStyleName="input-job-description" |
| 118 | + isDisabled |
| 119 | + stages={stages} |
| 120 | + buttonLabel="Submit Request" |
| 121 | + percentage="52" |
| 122 | + /> |
| 123 | + </div> |
| 124 | + ) : ( |
| 125 | + <div styleName="page"> |
| 126 | + <ResultCard /> |
| 127 | + <Completeness |
| 128 | + extraStyleName="input-job-description" |
| 129 | + stages={stages} |
| 130 | + buttonLabel="Submit Request" |
| 131 | + percentage="92" |
| 132 | + onClick={submitJob} |
| 133 | + /> |
| 134 | + <AddAnotherModal |
| 135 | + open={modalOpen} |
| 136 | + onClose={() => setModalOpen(false)} |
| 137 | + submitDone={submitDone} |
| 138 | + addAnother={addAnother} |
| 139 | + /> |
| 140 | + </div> |
| 141 | + )} |
| 142 | + </div> |
| 143 | + ); |
| 144 | +} |
| 145 | + |
| 146 | +InputJobDescription.propTypes = { |
| 147 | + projectId: PT.string, |
| 148 | +}; |
| 149 | + |
| 150 | +export default withAuthentication(InputJobDescription); |
0 commit comments