Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.25 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { AUTH_TOKEN, USER_ID, USER_DATA, USER_INFO, ACTIVE_PROJECT } from '../utils/constants';
  3. import { Container, Row, Col } from 'reactstrap';
  4. import Plan from './Plan';
  5.  
  6.  
  7. import gql from 'graphql-tag';
  8. import { Route, withRouter } from 'react-router-dom';
  9.  
  10. import { Query } from 'react-apollo';
  11. import { Button, Modal, ModalBody, Form, FormGroup, Label, Input } from 'reactstrap';
  12.  
  13.  
  14. import { Mutation } from 'react-apollo';
  15.  
  16.  
  17. const PLAN_MUTATION = gql`
  18. mutation($name: String!, $description: String!, $goal: Float!, $dueDate: String!, $isVerified: String!, $status: String!, $projectId: ID!, $userId: ID! ) {
  19. createPlan(name: $name, description: $description, goal: $goal, dueDate: $dueDate, isVerified: $isVerified, status: $status, projectId: $projectId, userId: $userId) {
  20. name
  21. description
  22. goal
  23. dueDate
  24. isVerified
  25. status
  26. projectId
  27. userId
  28. }
  29. }
  30. `;
  31.  
  32.  
  33. const PROJECT_QUERY = gql`
  34. query($id: ID!) {
  35. user(id: $id) {
  36. id
  37. email
  38. firstName
  39. plans {
  40. id
  41. name
  42. description
  43. status
  44. isVerified
  45. goal
  46. }
  47. }
  48. }
  49. `;
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. class PlanList extends Component {
  57.  
  58. constructor(props) {
  59. super(props);
  60.  
  61.  
  62. this.state = {
  63. name: '',
  64. description: '',
  65. goal: 0,
  66. dueDate: '',
  67. isVerified: "0",
  68. status: '',
  69. projectId: 0,
  70. userId: 0,
  71. modal: false,
  72. };
  73. this.toggle = this.toggle.bind(this);
  74. }
  75.  
  76.  
  77. toggle() {
  78. this.setState(prevState => ({
  79. modal: !prevState.modal,
  80.  
  81. }));
  82. }
  83.  
  84.  
  85.  
  86.  
  87. render() {
  88.  
  89. const userData = JSON.parse(localStorage.getItem(USER_DATA));
  90.  
  91. const id = userData.id;
  92.  
  93. const { name, description, goal, dueDate, isVerified, status } = this.state;
  94. console.log(userData);
  95. const userId = userData.id;
  96. const projectId = this.props.match.params.id;
  97.  
  98. return (
  99. <>
  100.  
  101. <Query query={PROJECT_QUERY} variables={{ id }}>
  102. {({ loading, error, data }) => {
  103. if (loading) return <div>Загрузка</div>
  104. if (error) return <div>Ошибка {error.message}</div>
  105.  
  106. const result = data.user;
  107. console.log(result);
  108.  
  109.  
  110. return (
  111. <>
  112. <div className="kanban-title">
  113. {result.firstName } у вас {result.plans.length } Сметы
  114. <span><Button onClick={this.toggle} >Новая смета</Button></span>
  115. </div>
  116.  
  117. <div className="kanban-workflow">
  118. <Row>
  119.  
  120.  
  121. {result.plans ? result.plans.map(plan => <Col xs={4}><Plan key={plan.id} plan={plan} smeta={result} /></Col>) : "Сметы по этому проекту не найдены"}
  122.  
  123. </Row>
  124. </div>
  125.  
  126. <Modal isOpen={this.state.modal} toggle={this.toggle} className="add-app-modal">
  127. <ModalBody>
  128. <Form>
  129. <Input type="hidden" value={projectId} onChange={e => this.setState({ projectId: e.target.value })} name="projectName" id="appNaprojectNameme" />
  130. <Input type="hidden" value={userId} onChange={e => this.setState({ userId: parseInt(e.target.value) })} name="userId" id="userId" />
  131. <Row className="alone">
  132. <Col xs={12}> <FormGroup>
  133.  
  134. <Input type="text" value={name} onChange={e => this.setState({ name: e.target.value })} name="appName" id="appName" placeholder="Введите название сметы" />
  135. </FormGroup></Col>
  136.  
  137.  
  138. </Row>
  139. <FormGroup>
  140. <Label for="content">Описание</Label>
  141. <Input type="textarea" rows={3} value={description} onChange={e => this.setState({ description: e.target.value })} name="content" id="content" placeholder="Распишите подробно задачу сметы" />
  142. </FormGroup>
  143.  
  144. <FormGroup row>
  145. <Col xs={6}>
  146. <Label for="exampleDatetime">Dead line</Label>
  147. <Input
  148. value={dueDate} onChange={e => this.setState({ dueDate: e.target.value })}
  149. type="date"
  150. name="dueDate"
  151. id="exampleDatetime"
  152. /></Col>
  153.  
  154. <Col xs={6}>
  155. <Label for="goal">Плановая сумма трат (грн)</Label>
  156. <Input
  157. value={goal} onChange={e => this.setState({ goal: parseInt(e.target.value) })}
  158. type="number"
  159. name="goal"
  160. id="goal"
  161. /></Col>
  162. </FormGroup>
  163. <FormGroup row>
  164. <Col xs={6}>
  165.  
  166. <Label>Одобрено директором (Только для директора)</Label>
  167. <Input type="select" value={isVerified} onChange={e => this.setState({ isVerified: e.target.value })}
  168. disabled={userData.role != 3 ? "disabled" : ""}
  169. name="status" id="status">
  170. <option value="0">- Не выбрано -</option>
  171. <option value="1">Не одобрено</option>
  172. <option value="2">Одобрено</option>
  173. <option value="3">Не одобрено, доработать</option>
  174. </Input>
  175. </Col>
  176. <Col xs={6}>
  177. <Label>Статус</Label>
  178. <Input type="select" value={status} onChange={e => this.setState({ status: e.target.value })} name="status" id="status"
  179. >
  180. <option value="0">Черновик</option>
  181. <option value="1">В Работе</option>
  182. <option value="2">Готово</option>
  183. </Input>
  184. </Col>
  185. </FormGroup>
  186.  
  187.  
  188. <FormGroup className="save-btn">
  189. <Mutation
  190. mutation={PLAN_MUTATION}
  191. variables={{ name, description, goal, status, isVerified, projectId, dueDate, userId }}
  192. onCompleted={() => this.props.history.go('/project' + projectId)}>
  193. {
  194. createPlan =>
  195. <Button color="primary " className="save" onClick={createPlan}>Создать</Button>
  196. }
  197. </Mutation>
  198. </FormGroup>
  199. </Form>
  200. </ModalBody>
  201. </Modal>
  202.  
  203.  
  204. </>
  205. )
  206. }}
  207. </Query>
  208. </>
  209. )
  210. }
  211. };
  212.  
  213. export default withRouter(PlanList);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement