@plusscommunities/pluss-maintenance-web 1.0.24 → 1.0.28-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -9,13 +9,13 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
9
9
  import _regeneratorRuntime from '@babel/runtime/regenerator';
10
10
  import React, { Component } from 'react';
11
11
  import { connect } from 'react-redux';
12
+ import { withRouter } from 'react-router';
12
13
  import _ from 'lodash';
13
14
  import moment from 'moment';
14
15
  import FontAwesome from 'react-fontawesome';
15
16
  import * as PlussCore from '@plusscommunities/pluss-core-web';
16
17
  import Cookies from 'js-cookie';
17
18
  import { Table, MenuItem, DropdownButton } from 'react-bootstrap';
18
- import { withRouter } from 'react-router';
19
19
  import { Link } from 'react-router-dom';
20
20
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
21
21
  import Textarea from 'react-textarea-autosize';
@@ -277,13 +277,14 @@ var maintenanceActions = {
277
277
  var Helper$3 = PlussCore.Helper,
278
278
  Session$5 = PlussCore.Session;
279
279
  var reactionActions = {
280
- addComment: function addComment(entityId, entityType, entityName, site, comment, image) {
280
+ addComment: function addComment(entityId, entityType, entityName, site, comment, image, parentId) {
281
281
  var data = {
282
282
  entityId: entityId,
283
283
  entityType: entityType,
284
284
  entityName: entityName,
285
285
  site: site,
286
- comment: comment
286
+ comment: comment,
287
+ parentId: parentId
287
288
  };
288
289
 
289
290
  if (!_.isEmpty(image)) {
@@ -424,8 +425,7 @@ var StatusTypes = {
424
425
  function _createSuper$a(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$a(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
425
426
 
426
427
  function _isNativeReflectConstruct$a() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
427
- var Session$4 = PlussCore.Session,
428
- Components$4 = PlussCore.Components;
428
+ var Session$4 = PlussCore.Session;
429
429
 
430
430
  var JobList = /*#__PURE__*/function (_Component) {
431
431
  _inherits(JobList, _Component);
@@ -533,10 +533,6 @@ var JobList = /*#__PURE__*/function (_Component) {
533
533
  };
534
534
  }());
535
535
 
536
- _defineProperty(_assertThisInitialized(_this), "onOpenJobTypes", function () {
537
- _this.props.history.push('/requestTypes');
538
- });
539
-
540
536
  _this.state = {
541
537
  showCompleted: false,
542
538
  sortColumn: 'createdUnix',
@@ -676,27 +672,6 @@ var JobList = /*#__PURE__*/function (_Component) {
676
672
  }
677
673
  }, "Example might be; Fix my light bulb, hand rail is broken, or please send flowers to Mum."));
678
674
  }
679
- }, {
680
- key: "renderButtons",
681
- value: function renderButtons() {
682
- if (!Session$4.validateAccess(this.props.auth.site, 'maintenanceTypes', this.props.auth)) return null;
683
- return /*#__PURE__*/React.createElement("div", {
684
- className: "flex-reverse"
685
- }, /*#__PURE__*/React.createElement(Components$4.Button, {
686
- inline: true,
687
- buttonType: "primaryAction",
688
- onClick: this.onOpenJobTypes,
689
- isActive: true
690
- }, /*#__PURE__*/React.createElement("div", {
691
- className: "flex flex-row flex-center"
692
- }, /*#__PURE__*/React.createElement(Components$4.SVGIcon, {
693
- colour: '#fff',
694
- icon: "maintenance2",
695
- height: "17px"
696
- }), /*#__PURE__*/React.createElement("div", {
697
- className: "marginLeft-10"
698
- }, "Request Types"))));
699
- }
700
675
  }, {
701
676
  key: "renderContent",
702
677
  value: function renderContent() {
@@ -768,7 +743,7 @@ var JobList = /*#__PURE__*/function (_Component) {
768
743
  style: {
769
744
  minWidth: '100%'
770
745
  }
771
- }, this.renderButtons(), this.renderContent(), /*#__PURE__*/React.createElement("div", {
746
+ }, this.renderContent(), /*#__PURE__*/React.createElement("div", {
772
747
  className: "hub_tidioPadding"
773
748
  }));
774
749
  }
@@ -794,1308 +769,1235 @@ var JobList$1 = connect(mapStateToProps$4, {
794
769
  function _createSuper$9(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$9(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
795
770
 
796
771
  function _isNativeReflectConstruct$9() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
797
- var Components$3 = PlussCore.Components,
798
- Session$3 = PlussCore.Session;
772
+ var Session$3 = PlussCore.Session,
773
+ Components$3 = PlussCore.Components,
774
+ Helper$2 = PlussCore.Helper;
799
775
 
800
- var RequestsHub = /*#__PURE__*/function (_Component) {
801
- _inherits(RequestsHub, _Component);
776
+ var JobTypes = /*#__PURE__*/function (_Component) {
777
+ _inherits(JobTypes, _Component);
802
778
 
803
- var _super = _createSuper$9(RequestsHub);
779
+ var _super = _createSuper$9(JobTypes);
804
780
 
805
- function RequestsHub(props) {
781
+ function JobTypes(props) {
806
782
  var _this;
807
783
 
808
- _classCallCheck(this, RequestsHub);
784
+ _classCallCheck(this, JobTypes);
809
785
 
810
786
  _this = _super.call(this, props);
811
787
 
812
- _defineProperty(_assertThisInitialized(_this), "setData", function () {
813
- var allList = [];
788
+ _defineProperty(_assertThisInitialized(_this), "getJobTypes", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
789
+ var res;
790
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
791
+ while (1) {
792
+ switch (_context.prev = _context.next) {
793
+ case 0:
794
+ _context.prev = 0;
795
+ _context.next = 3;
796
+ return maintenanceActions.getJobTypes(_this.props.auth.site);
814
797
 
815
- _this.state.allList.forEach(function (ev) {
816
- if (ev != null && !ev.Deleted) allList.push(ev);
817
- });
798
+ case 3:
799
+ res = _context.sent;
800
+ if (res.data != null) _this.props.jobTypesLoaded(res.data);
801
+ _context.next = 10;
802
+ break;
818
803
 
819
- var upcoming = _.filter(allList, function (ev) {
820
- if (!ev) return false;
821
- if (ev.status && ev.status === 'Completed') return false;
822
- return true;
823
- });
804
+ case 7:
805
+ _context.prev = 7;
806
+ _context.t0 = _context["catch"](0);
807
+ console.error('getJobTypes', _context.t0);
824
808
 
825
- var completed = _.filter(allList, function (ev) {
826
- if (!ev) return false;
827
- if (ev.status && ev.status === 'Completed') return true;
828
- return false;
829
- }); // console.log('setData', upcoming, completed);
809
+ case 10:
810
+ _context.prev = 10;
830
811
 
812
+ _this.setState({
813
+ loading: false
814
+ });
831
815
 
832
- _this.setState({
833
- allList: allList,
834
- upcoming: upcoming,
835
- completed: completed
836
- });
816
+ return _context.finish(10);
817
+
818
+ case 13:
819
+ case "end":
820
+ return _context.stop();
821
+ }
822
+ }
823
+ }, _callee, null, [[0, 7, 10, 13]]);
824
+ })));
825
+
826
+ _defineProperty(_assertThisInitialized(_this), "sortByCol", function (col) {
827
+ if (_this.state.sortColumn === col) {
828
+ _this.setState({
829
+ sortDesc: !_this.state.sortDesc
830
+ });
831
+ } else {
832
+ _this.setState({
833
+ sortColumn: col,
834
+ sortDesc: false
835
+ });
836
+ }
837
837
  });
838
838
 
839
- _defineProperty(_assertThisInitialized(_this), "getData", function () {
840
- var auth = _this.props.auth;
839
+ _defineProperty(_assertThisInitialized(_this), "validateEmail", function () {
840
+ var jobTypeEmail = _this.state.jobTypeEmail;
841
+ return !_.isEmpty(jobTypeEmail) && Helper$2.isEmail(jobTypeEmail);
842
+ });
841
843
 
842
- _this.setState({
843
- loadingAll: true
844
- }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
845
- var res;
846
- return _regeneratorRuntime.wrap(function _callee$(_context) {
844
+ _defineProperty(_assertThisInitialized(_this), "isJobTypeValid", function () {
845
+ var _this$state = _this.state,
846
+ jobTypeName = _this$state.jobTypeName,
847
+ jobTypeDescription = _this$state.jobTypeDescription;
848
+ if (_.isEmpty(jobTypeName)) return false;
849
+ if (!_this.validateEmail()) return false;
850
+ if (_.isEmpty(jobTypeDescription)) return false;
851
+ return true;
852
+ });
853
+
854
+ _defineProperty(_assertThisInitialized(_this), "onRemoveJobType", /*#__PURE__*/function () {
855
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(ev) {
856
+ var index, newJobTypes;
857
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
847
858
  while (1) {
848
- switch (_context.prev = _context.next) {
859
+ switch (_context2.prev = _context2.next) {
849
860
  case 0:
850
- _context.prev = 0;
851
- _context.next = 3;
852
- return maintenanceActions.getJobs(auth.site);
861
+ if (window.confirm("Are you sure you want to delete ".concat(ev.typeName, "?"))) {
862
+ _context2.next = 2;
863
+ break;
864
+ }
853
865
 
854
- case 3:
855
- res = _context.sent;
866
+ return _context2.abrupt("return");
856
867
 
857
- // console.log('getData', res.data);
858
- _this.setState({
859
- loadingAll: false
868
+ case 2:
869
+ _context2.prev = 2;
870
+ _context2.next = 5;
871
+ return maintenanceActions.deleteJobType(_this.props.auth.site, ev.id);
872
+
873
+ case 5:
874
+ index = _.findIndex(_this.state.jobList, function (job) {
875
+ return job != null && job.id === ev.id;
860
876
  });
861
877
 
862
- if (res.data != null && !_.isEmpty(res.data) && res.data[0].site === auth.site) {
863
- _this.props.jobsLoaded(res.data);
878
+ if (index > -1) {
879
+ newJobTypes = _toConsumableArray(_this.state.jobList);
880
+ newJobTypes[index].Deleted = true;
881
+
882
+ _this.props.jobTypesLoaded(newJobTypes);
864
883
  }
865
884
 
866
- _context.next = 12;
885
+ _context2.next = 13;
867
886
  break;
868
887
 
869
- case 8:
870
- _context.prev = 8;
871
- _context.t0 = _context["catch"](0);
872
- console.error('getData', _context.t0);
873
-
874
- _this.setState({
875
- loadingAll: false
876
- });
888
+ case 9:
889
+ _context2.prev = 9;
890
+ _context2.t0 = _context2["catch"](2);
891
+ console.error('onRemoveJobType', _context2.t0);
892
+ alert('Something went wrong with the request. Please try again.');
877
893
 
878
- case 12:
894
+ case 13:
879
895
  case "end":
880
- return _context.stop();
896
+ return _context2.stop();
881
897
  }
882
898
  }
883
- }, _callee, null, [[0, 8]]);
884
- })));
885
- });
899
+ }, _callee2, null, [[2, 9]]);
900
+ }));
886
901
 
887
- _defineProperty(_assertThisInitialized(_this), "onAddNew", function () {
888
- var auth = _this.props.auth;
902
+ return function (_x) {
903
+ return _ref2.apply(this, arguments);
904
+ };
905
+ }());
889
906
 
890
- if (Session$3.validateAccess(auth.site, 'maintenanceTracking', auth)) {
891
- _this.props.history.push("/requestsHub/job");
892
- }
893
- });
907
+ _defineProperty(_assertThisInitialized(_this), "onShowJobType", function () {
908
+ var job = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
894
909
 
895
- _defineProperty(_assertThisInitialized(_this), "canAddNew", function (isClass) {
896
- var auth = _this.props.auth;
897
- if (Session$3.validateAccess(auth.site, 'maintenanceTracking', auth)) return isClass ? '' : true;
898
- return isClass ? ' hub-sideContent-topButton--hide' : false;
910
+ _this.setState({
911
+ showJobType: true,
912
+ jobTypeId: job ? job.id : null,
913
+ jobTypeName: job ? job.typeName : '',
914
+ jobTypeEmail: job ? job.email : '',
915
+ jobTypeDescription: job ? job.description : '',
916
+ jobTypeLevel: job ? job.level : 1
917
+ });
899
918
  });
900
919
 
901
- _defineProperty(_assertThisInitialized(_this), "getSideBarSectionColour", function (id) {
902
- return _this.state.selectedSection === id ? {
903
- backgroundColor: '#fff'
904
- } : {};
905
- });
920
+ _defineProperty(_assertThisInitialized(_this), "onHideJobType", function () {
921
+ if (_this.state.submitting) return;
906
922
 
907
- _defineProperty(_assertThisInitialized(_this), "renderStats", function (stat, loading) {
908
- return loading ? /*#__PURE__*/React.createElement(FontAwesome, {
909
- style: styles$4.spinner,
910
- name: "spinner fa-pulse fa-fw"
911
- }) : stat;
923
+ _this.setState({
924
+ showWarnings: false,
925
+ showJobType: false,
926
+ jobTypeId: null,
927
+ jobTypeName: '',
928
+ jobTypeEmail: '',
929
+ jobTypeDescription: '',
930
+ jobTypeLevel: 1
931
+ });
912
932
  });
913
933
 
914
- _this.state = {
915
- selectedSection: 'upcoming',
916
- location: '',
917
- loadingAll: false,
918
- loadingSubmissions: false,
919
- submissionEntries: [],
920
- allList: [],
921
- completed: [],
922
- upcoming: [],
923
- now: moment.utc(),
924
- onlyFuture: true,
925
- search: ''
926
- };
927
- return _this;
928
- }
934
+ _defineProperty(_assertThisInitialized(_this), "onHandleChange", function (event) {
935
+ var stateChange = {};
936
+ stateChange[event.target.getAttribute('id')] = event.target.value;
929
937
 
930
- _createClass(RequestsHub, [{
931
- key: "UNSAFE_componentWillMount",
932
- value: function UNSAFE_componentWillMount() {
933
- this.updateProps(this.props);
934
- }
935
- }, {
936
- key: "componentDidMount",
937
- value: function componentDidMount() {
938
- this.getData();
939
- }
940
- }, {
941
- key: "UNSAFE_componentWillReceiveProps",
942
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
943
- if (!_.isEqual(this.props.jobs, nextProps.jobs)) this.updateProps(nextProps);
944
- }
945
- }, {
946
- key: "updateProps",
947
- value: function updateProps(props) {
948
- this.setState({
949
- allList: props.jobs
950
- }, this.setData);
951
- }
952
- }, {
953
- key: "renderLeftBar",
954
- value: function renderLeftBar() {
955
- var _this2 = this;
938
+ _this.setState(stateChange);
939
+ });
956
940
 
957
- return /*#__PURE__*/React.createElement("div", {
958
- className: "hub-sideContent"
959
- }, /*#__PURE__*/React.createElement("div", {
960
- className: "hub-sideContent-topButton"
961
- }), /*#__PURE__*/React.createElement("div", {
962
- style: {
963
- paddingLeft: 15,
964
- width: '100%'
965
- }
966
- }, /*#__PURE__*/React.createElement("div", {
967
- className: "fontMedium fontSize-32 text-dark",
968
- style: styles$4.sideBarTitleSection
969
- }, "Maintenance requests"), /*#__PURE__*/React.createElement("div", {
970
- onClick: function onClick() {
971
- _this2.setState({
972
- selectedSection: 'completed'
973
- });
974
- },
975
- className: "sideBarSection",
976
- style: this.getSideBarSectionColour('completed')
977
- }, /*#__PURE__*/React.createElement("div", {
978
- className: "fontMedium fontSize-36 text-dark",
979
- style: {
980
- lineHeight: '50px'
981
- }
982
- }, this.renderStats(this.state.completed.length, this.state.loadingAll)), /*#__PURE__*/React.createElement("div", {
983
- className: "fontRegular fontSize-16 text-light lineHeight-22"
984
- }, "Complete")), /*#__PURE__*/React.createElement("div", {
985
- onClick: function onClick() {
986
- _this2.setState({
987
- selectedSection: 'upcoming'
988
- });
989
- },
990
- className: "sideBarSection",
991
- style: this.getSideBarSectionColour('upcoming')
992
- }, /*#__PURE__*/React.createElement("div", {
993
- className: "fontMedium fontSize-36 text-dark",
994
- style: {
995
- lineHeight: '50px'
996
- }
997
- }, this.renderStats(this.state.upcoming.length, this.state.loadingAll)), /*#__PURE__*/React.createElement("div", {
998
- className: "fontRegular fontSize-16 text-light lineHeight-22"
999
- }, "Incomplete"))));
1000
- }
1001
- }, {
1002
- key: "renderRight",
1003
- value: function renderRight() {
1004
- return /*#__PURE__*/React.createElement(JobList$1, {
1005
- source: this.state.selectedSection === 'completed' ? this.state.completed : this.state.upcoming
1006
- });
1007
- }
1008
- }, {
1009
- key: "render",
1010
- value: function render() {
1011
- return /*#__PURE__*/React.createElement("div", {
1012
- className: "hub-wrapperContainer"
1013
- }, this.renderLeftBar(), /*#__PURE__*/React.createElement("div", {
1014
- className: "hub-headerContentWrapper"
1015
- }, /*#__PURE__*/React.createElement(Components$3.Header, null, this.canAddNew() && /*#__PURE__*/React.createElement(Components$3.AddButton, {
1016
- onClick: this.onAddNew,
1017
- text: "NEW REQUEST"
1018
- })), /*#__PURE__*/React.createElement("div", {
1019
- className: "hub-contentWrapper"
1020
- }, this.renderRight())));
1021
- }
1022
- }]);
1023
-
1024
- return RequestsHub;
1025
- }(Component);
1026
-
1027
- var styles$4 = {
1028
- sideBarTitleSection: {
1029
- lineHeight: '40px',
1030
- marginTop: 30,
1031
- marginBottom: 30,
1032
- paddingLeft: 24,
1033
- paddingRight: 24
1034
- },
1035
- sideBarSection: {
1036
- weight: '100%',
1037
- minWidth: 200,
1038
- padding: 32,
1039
- paddingLeft: 24,
1040
- cursor: 'pointer',
1041
- display: 'flex',
1042
- flexDirection: 'column',
1043
- justifyContent: 'center'
1044
- },
1045
- spinner: {
1046
- fontSize: 32,
1047
- color: FeatureConfig.env.colourBrandingOff
1048
- }
1049
- };
1050
-
1051
- var mapStateToProps$3 = function mapStateToProps(state) {
1052
- var jobs = state.maintenance.jobs;
1053
- var auth = state.auth;
1054
- return {
1055
- jobs: jobs,
1056
- auth: auth
1057
- };
1058
- };
1059
-
1060
- var RequestsHub$1 = connect(mapStateToProps$3, {
1061
- jobsLoaded: jobsLoaded
1062
- })(RequestsHub);
1063
-
1064
- function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1065
-
1066
- function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1067
-
1068
- function _createSuper$8(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$8(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
941
+ _defineProperty(_assertThisInitialized(_this), "onSave", function () {
942
+ var site = _this.props.auth.site;
943
+ var _this$state2 = _this.state,
944
+ submitting = _this$state2.submitting,
945
+ jobTypeId = _this$state2.jobTypeId,
946
+ jobTypeName = _this$state2.jobTypeName,
947
+ jobTypeEmail = _this$state2.jobTypeEmail,
948
+ jobTypeDescription = _this$state2.jobTypeDescription,
949
+ jobTypeLevel = _this$state2.jobTypeLevel;
950
+ if (submitting) return;
1069
951
 
1070
- function _isNativeReflectConstruct$8() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1071
- var Apis = PlussCore.Apis,
1072
- Helper$2 = PlussCore.Helper,
1073
- Session$2 = PlussCore.Session,
1074
- Colours = PlussCore.Colours,
1075
- Components$2 = PlussCore.Components;
952
+ if (!_this.isJobTypeValid()) {
953
+ _this.setState({
954
+ showWarnings: true
955
+ });
1076
956
 
1077
- var Job = /*#__PURE__*/function (_Component) {
1078
- _inherits(Job, _Component);
957
+ return;
958
+ }
1079
959
 
1080
- var _super = _createSuper$8(Job);
960
+ _this.setState({
961
+ submitting: true
962
+ }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
963
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
964
+ while (1) {
965
+ switch (_context3.prev = _context3.next) {
966
+ case 0:
967
+ _context3.prev = 0;
1081
968
 
1082
- function Job(props) {
1083
- var _this;
969
+ if (!jobTypeId) {
970
+ _context3.next = 6;
971
+ break;
972
+ }
1084
973
 
1085
- _classCallCheck(this, Job);
974
+ _context3.next = 4;
975
+ return maintenanceActions.editJobType(site, jobTypeId, jobTypeName, jobTypeEmail, jobTypeDescription, jobTypeLevel);
1086
976
 
1087
- _this = _super.call(this, props);
977
+ case 4:
978
+ _context3.next = 8;
979
+ break;
1088
980
 
1089
- _defineProperty(_assertThisInitialized(_this), "getJob", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1090
- var res;
1091
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1092
- while (1) {
1093
- switch (_context.prev = _context.next) {
1094
- case 0:
1095
- _context.prev = 0;
1096
- _context.next = 3;
1097
- return maintenanceActions.getJob(_this.props.auth.site, _this.state.jobId);
981
+ case 6:
982
+ _context3.next = 8;
983
+ return maintenanceActions.addJobType(site, jobTypeName, jobTypeEmail, jobTypeDescription, jobTypeLevel);
1098
984
 
1099
- case 3:
1100
- res = _context.sent;
985
+ case 8:
986
+ _this.props.jobTypesUpdate(site);
1101
987
 
1102
- _this.setState({
1103
- updating: false
1104
- });
988
+ _this.setState({
989
+ submitting: false
990
+ }, _this.onHideJobType);
1105
991
 
1106
- res.data.location = res.data.site;
992
+ _context3.next = 17;
993
+ break;
1107
994
 
1108
- _this.setJob(res.data);
995
+ case 12:
996
+ _context3.prev = 12;
997
+ _context3.t0 = _context3["catch"](0);
998
+ console.error('onSave', _context3.t0);
1109
999
 
1110
- _context.next = 12;
1111
- break;
1000
+ _this.setState({
1001
+ submitting: false
1002
+ });
1112
1003
 
1113
- case 9:
1114
- _context.prev = 9;
1115
- _context.t0 = _context["catch"](0);
1116
- console.error('getJob', _context.t0);
1004
+ alert('Something went wrong with the request. Please try again.');
1117
1005
 
1118
- case 12:
1119
- case "end":
1120
- return _context.stop();
1006
+ case 17:
1007
+ case "end":
1008
+ return _context3.stop();
1009
+ }
1121
1010
  }
1122
- }
1123
- }, _callee, null, [[0, 9]]);
1124
- })));
1125
-
1126
- _defineProperty(_assertThisInitialized(_this), "setJob", function (job) {
1127
- job.typeIcon = job.type === 'General' ? 'wrench' : 'tree';
1128
- job.typeColour = job.type === 'General' ? '#666' : 'green';
1129
-
1130
- if (_.isEmpty(job.lastActivity)) {
1131
- job.lastActivity = '-- --';
1132
- job.noActivity = true;
1133
- }
1134
-
1135
- if (_.isEmpty(job.status)) {
1136
- job.status = 'Unassigned';
1137
- job.notStatus = true;
1138
- }
1139
-
1140
- if (_.isEmpty(job.audience)) {
1141
- job.audience = [{
1142
- displayName: 'Unassigned',
1143
- isEmpty: true
1144
- }];
1145
- }
1146
-
1147
- var needToMarkSeen = false;
1011
+ }, _callee3, null, [[0, 12]]);
1012
+ })));
1013
+ });
1148
1014
 
1149
- if (!job.seen) {
1150
- job.seen = true;
1151
- needToMarkSeen = true;
1152
- }
1015
+ _this.state = {
1016
+ jobList: [],
1017
+ showCompleted: false,
1018
+ sortColumn: 'name',
1019
+ sortDesc: false,
1020
+ loading: true,
1021
+ showJobType: false,
1022
+ jobTypeId: null,
1023
+ jobTypeName: '',
1024
+ jobTypeEmail: '',
1025
+ jobTypeDescription: '',
1026
+ jobTypeLevel: 1,
1027
+ showWarnings: false,
1028
+ submitting: false
1029
+ };
1030
+ return _this;
1031
+ }
1153
1032
 
1154
- _this.setState({
1155
- job: job
1156
- }, function () {
1157
- if (needToMarkSeen) _this.markSeen();
1033
+ _createClass(JobTypes, [{
1034
+ key: "componentWillMount",
1035
+ value: function componentWillMount() {
1036
+ this.updateProps(this.props);
1037
+ Session$3.checkLoggedIn(this, this.props.auth);
1038
+ }
1039
+ }, {
1040
+ key: "componentDidMount",
1041
+ value: function componentDidMount() {
1042
+ this.getJobTypes();
1043
+ }
1044
+ }, {
1045
+ key: "componentWillReceiveProps",
1046
+ value: function componentWillReceiveProps(nextProps) {
1047
+ this.updateProps(nextProps);
1048
+ }
1049
+ }, {
1050
+ key: "updateProps",
1051
+ value: function updateProps(props) {
1052
+ this.setState({
1053
+ jobList: props.jobtypes
1158
1054
  });
1055
+ }
1056
+ }, {
1057
+ key: "renderList",
1058
+ value: function renderList() {
1059
+ var _this2 = this;
1159
1060
 
1160
- _this.props.jobsLoaded([job]);
1161
- });
1162
-
1163
- _defineProperty(_assertThisInitialized(_this), "editJob", function () {});
1061
+ var source = _.sortBy(this.state.jobList, this.state.sortColumn);
1164
1062
 
1165
- _defineProperty(_assertThisInitialized(_this), "isReadyToSaveNote", function () {
1166
- var _this$state = _this.state,
1167
- noteAttachments = _this$state.noteAttachments,
1168
- noteInput = _this$state.noteInput;
1169
- if (_.some(noteAttachments, function (n) {
1170
- return n.Uploading;
1171
- })) return false;
1172
- return !_.isEmpty(noteInput) || !_.isEmpty(noteAttachments);
1173
- });
1174
-
1175
- _defineProperty(_assertThisInitialized(_this), "onOpenAddNote", function () {
1176
- _this.setState({
1177
- addNoteOpen: true,
1178
- editingNote: null
1179
- });
1180
- });
1181
-
1182
- _defineProperty(_assertThisInitialized(_this), "onCloseAddNote", function () {
1183
- var newState = {
1184
- addNoteOpen: false,
1185
- editingNote: null
1186
- };
1187
-
1188
- if (!!_this.state.editingNote) {
1189
- newState.noteInput = '';
1190
- newState.noteAttachments = [];
1191
- }
1192
-
1193
- _this.setState(newState);
1194
- });
1195
-
1196
- _defineProperty(_assertThisInitialized(_this), "onOpenNoteMenu", function (index) {
1197
- if (_this.state.noteMenuOpen === index) {
1198
- _this.setState({
1199
- noteMenuOpen: null
1200
- });
1201
- } else {
1202
- _this.setState({
1203
- noteMenuOpen: index
1204
- });
1205
- }
1206
- });
1207
-
1208
- _defineProperty(_assertThisInitialized(_this), "onHandlePDFFileChange", function (event) {
1209
- var file = event.target.files[0];
1210
- if (!file || _this.state.uploadingNoteAttachment) return;
1211
-
1212
- var noteAttachments = _toConsumableArray(_this.state.noteAttachments);
1213
-
1214
- var newAttachment = {
1215
- Uploading: true,
1216
- Title: file.name
1217
- };
1218
- noteAttachments.push(newAttachment);
1219
-
1220
- _this.setState({
1221
- noteAttachments: noteAttachments
1063
+ if (this.state.sortDesc) source.reverse();
1064
+ source = _.filter(source, function (ev) {
1065
+ if (!ev) return false;
1066
+ if (ev.Deleted) return false;
1067
+ return true;
1222
1068
  });
1069
+ return source.map(function (ev, index) {
1070
+ if (ev != null) {
1071
+ return /*#__PURE__*/React.createElement("tr", {
1072
+ key: index
1073
+ }, /*#__PURE__*/React.createElement("td", {
1074
+ className: "table-TitleColumn"
1075
+ }, /*#__PURE__*/React.createElement("a", {
1076
+ onClick: function onClick() {
1077
+ return _this2.onShowJobType(ev);
1078
+ }
1079
+ }, ev.typeName)), /*#__PURE__*/React.createElement("td", null, ev.description), /*#__PURE__*/React.createElement("td", null, ev.email), /*#__PURE__*/React.createElement("td", {
1080
+ className: "table-options"
1081
+ }, /*#__PURE__*/React.createElement("div", {
1082
+ style: {
1083
+ display: 'flex',
1084
+ alignItems: 'center'
1085
+ }
1086
+ }, Session$3.validateAccess(_this2.props.auth.site, 'maintenanceTypes', _this2.props.auth) && /*#__PURE__*/React.createElement("a", {
1087
+ onClick: function onClick() {
1088
+ return _this2.onShowJobType(ev);
1089
+ }
1090
+ }, /*#__PURE__*/React.createElement(FontAwesome, {
1091
+ style: {
1092
+ fontSize: 20,
1093
+ padding: 5,
1094
+ marginLeft: 12,
1095
+ cursor: 'pointer'
1096
+ },
1097
+ name: "pencil"
1098
+ })), Session$3.validateAccess(_this2.props.auth.site, 'maintenanceTypes', _this2.props.auth) && /*#__PURE__*/React.createElement("a", {
1099
+ onClick: function onClick() {
1100
+ return _this2.onRemoveJobType(ev);
1101
+ }
1102
+ }, /*#__PURE__*/React.createElement(FontAwesome, {
1103
+ style: {
1104
+ fontSize: 20,
1105
+ padding: 5,
1106
+ marginLeft: 8,
1107
+ cursor: 'pointer'
1108
+ },
1109
+ name: "minus-circle"
1110
+ })))));
1111
+ }
1223
1112
 
1224
- Apis.fileActions.uploadMediaAsync(file, file.name).then(function (fileRes) {
1225
- newAttachment.Source = fileRes;
1226
- newAttachment.Uploading = false;
1227
-
1228
- _this.setState({
1229
- noteAttachments: _toConsumableArray(_this.state.noteAttachments)
1230
- });
1231
- }).catch(function (uploadErrorRes) {
1232
- console.log(uploadErrorRes);
1233
- newAttachment.Uploading = false;
1234
-
1235
- _this.setState({
1236
- noteAttachments: _toConsumableArray(_this.state.noteAttachments)
1237
- });
1113
+ return null;
1238
1114
  });
1239
- event.target.value = '';
1240
- });
1241
-
1242
- _defineProperty(_assertThisInitialized(_this), "onRemoveAttachment", function (a) {
1243
- var index = _this.state.noteAttachments.indexOf(a);
1115
+ }
1116
+ }, {
1117
+ key: "renderView",
1118
+ value: function renderView() {
1119
+ var _this3 = this;
1244
1120
 
1245
- if (index > -1) {
1246
- var newAttachments = _toConsumableArray(_this.state.noteAttachments);
1121
+ return /*#__PURE__*/React.createElement(Table, {
1122
+ className: "plussTable",
1123
+ striped: true,
1124
+ bordered: true,
1125
+ condensed: true,
1126
+ hover: true,
1127
+ style: {
1128
+ minWidth: '100%'
1129
+ }
1130
+ }, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", {
1131
+ style: {
1132
+ cursor: 'pointer'
1133
+ },
1134
+ onClick: function onClick() {
1135
+ return _this3.sortByCol('name');
1136
+ }
1137
+ }, "Request type"), /*#__PURE__*/React.createElement("th", {
1138
+ style: {
1139
+ cursor: 'pointer'
1140
+ },
1141
+ onClick: function onClick() {
1142
+ return _this3.sortByCol('name');
1143
+ }
1144
+ }, "Type Description"), /*#__PURE__*/React.createElement("th", {
1145
+ style: {
1146
+ cursor: 'pointer'
1147
+ },
1148
+ onClick: function onClick() {
1149
+ return _this3.sortByCol('email');
1150
+ }
1151
+ }, "Email"), /*#__PURE__*/React.createElement("th", {
1152
+ style: {
1153
+ width: 70
1154
+ }
1155
+ }))), /*#__PURE__*/React.createElement("tbody", null, this.renderList()));
1156
+ }
1157
+ }, {
1158
+ key: "renderEmpty",
1159
+ value: function renderEmpty() {
1160
+ return /*#__PURE__*/React.createElement("div", {
1161
+ style: {
1162
+ display: 'flex',
1163
+ flexDirection: 'column',
1164
+ flex: 1,
1165
+ justifyContent: 'center',
1166
+ alignItems: 'center',
1167
+ marginTop: 32
1168
+ }
1169
+ }, /*#__PURE__*/React.createElement("div", {
1170
+ className: "emptyState"
1171
+ }), /*#__PURE__*/React.createElement("div", {
1172
+ className: "marginTop-32",
1173
+ style: {
1174
+ maxWidth: 500,
1175
+ textAlign: 'center'
1176
+ }
1177
+ }, /*#__PURE__*/React.createElement("span", {
1178
+ className: "fontRegular fontSize-13"
1179
+ }, "Please add the many categories of request types that exist in your village which work alongside the Maintenance area.")), /*#__PURE__*/React.createElement("div", {
1180
+ className: "marginTop-8 fontRegular fontSize-13",
1181
+ style: {
1182
+ maxWidth: 500,
1183
+ textAlign: 'center'
1184
+ }
1185
+ }, "Examples might be; OH&S, Electrical, General. Remember to add a description too."));
1186
+ }
1187
+ }, {
1188
+ key: "renderContent",
1189
+ value: function renderContent() {
1190
+ if (_.isEmpty(this.state.jobList)) return this.renderEmpty();
1191
+ return this.renderView();
1192
+ }
1193
+ }, {
1194
+ key: "renderJobTypes",
1195
+ value: function renderJobTypes() {
1196
+ var _this4 = this;
1247
1197
 
1248
- newAttachments.splice(index, 1);
1198
+ var _this$state3 = this.state,
1199
+ jobList = _this$state3.jobList,
1200
+ loading = _this$state3.loading;
1249
1201
 
1250
- _this.setState({
1251
- noteAttachments: newAttachments
1252
- });
1202
+ if (jobList.length === 0 && loading) {
1203
+ return /*#__PURE__*/React.createElement("div", {
1204
+ style: {
1205
+ minWidth: '100%'
1206
+ }
1207
+ }, /*#__PURE__*/React.createElement("div", {
1208
+ className: "padding-60 paddingVertical-40",
1209
+ style: {
1210
+ textAlign: 'center'
1211
+ }
1212
+ }, /*#__PURE__*/React.createElement(FontAwesome, {
1213
+ style: {
1214
+ fontSize: 30,
1215
+ color: FeatureConfig.env.colourBrandingOff
1216
+ },
1217
+ name: "spinner fa-pulse fa-fw"
1218
+ })));
1253
1219
  }
1254
- });
1255
-
1256
- _defineProperty(_assertThisInitialized(_this), "onConfirmAddNote", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
1257
- var res;
1258
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1259
- while (1) {
1260
- switch (_context2.prev = _context2.next) {
1261
- case 0:
1262
- if (_this.isReadyToSaveNote()) {
1263
- _context2.next = 2;
1264
- break;
1265
- }
1266
1220
 
1267
- return _context2.abrupt("return");
1268
-
1269
- case 2:
1270
- _context2.prev = 2;
1221
+ return /*#__PURE__*/React.createElement("div", {
1222
+ style: {
1223
+ minWidth: '100%'
1224
+ }
1225
+ }, /*#__PURE__*/React.createElement("div", {
1226
+ className: "marginBottom-32"
1227
+ }, /*#__PURE__*/React.createElement(Components$3.AddButton, {
1228
+ onClick: function onClick() {
1229
+ return _this4.onShowJobType();
1230
+ },
1231
+ text: "NEW REQUEST TYPE"
1232
+ })), this.renderContent());
1233
+ }
1234
+ }, {
1235
+ key: "renderNewUserTypePopup",
1236
+ value: function renderNewUserTypePopup() {
1237
+ var _this5 = this;
1271
1238
 
1272
- _this.setState({
1273
- submittingNote: true
1274
- });
1239
+ var _this$state4 = this.state,
1240
+ submitting = _this$state4.submitting,
1241
+ showJobType = _this$state4.showJobType,
1242
+ jobTypeId = _this$state4.jobTypeId,
1243
+ showWarnings = _this$state4.showWarnings,
1244
+ jobTypeName = _this$state4.jobTypeName,
1245
+ jobTypeEmail = _this$state4.jobTypeEmail,
1246
+ jobTypeDescription = _this$state4.jobTypeDescription;
1247
+ if (!showJobType) return null;
1248
+ return /*#__PURE__*/React.createElement(Components$3.Popup, {
1249
+ maxWidth: 800,
1250
+ hasPadding: true,
1251
+ buttons: [{
1252
+ type: 'primaryAction',
1253
+ onClick: this.onSave,
1254
+ isActive: !submitting && this.isJobTypeValid(),
1255
+ text: submitting ? 'Saving...' : 'Save',
1256
+ className: 'popupButton'
1257
+ }, {
1258
+ type: 'outlinedAction',
1259
+ onClick: this.onHideJobType,
1260
+ isActive: !submitting,
1261
+ text: 'Cancel',
1262
+ className: 'popupButton'
1263
+ }],
1264
+ onClose: this.onHideJobType,
1265
+ title: jobTypeId ? 'Edit Request Type' : 'Create New Request Type'
1266
+ }, /*#__PURE__*/React.createElement(Components$3.GenericInput, {
1267
+ id: "jobTypeName",
1268
+ type: "text",
1269
+ label: "Request type title",
1270
+ placeholder: "Request type title",
1271
+ value: jobTypeName,
1272
+ onChange: this.onHandleChange,
1273
+ isRequired: true,
1274
+ isValid: function isValid() {
1275
+ return !_.isEmpty(jobTypeName);
1276
+ },
1277
+ showError: function showError() {
1278
+ return showWarnings && _.isEmpty(jobTypeName);
1279
+ },
1280
+ alwaysShowLabel: true
1281
+ }), /*#__PURE__*/React.createElement(Components$3.GenericInput, {
1282
+ id: "jobTypeEmail",
1283
+ type: "text",
1284
+ label: "Email",
1285
+ placeholder: "Request email",
1286
+ help: "This is the email address that'll receive service requests of this type",
1287
+ value: jobTypeEmail,
1288
+ onChange: this.onHandleChange,
1289
+ isRequired: true,
1290
+ isValid: this.validateEmail,
1291
+ showError: function showError() {
1292
+ return showWarnings && !_this5.validateEmail();
1293
+ },
1294
+ alwaysShowLabel: true
1295
+ }), /*#__PURE__*/React.createElement(Components$3.GenericInput, {
1296
+ id: "jobTypeDescription",
1297
+ type: "text",
1298
+ label: "Description",
1299
+ placeholder: "Add a description. ",
1300
+ help: "This description will be visible to the people to help them select the correct request type.",
1301
+ value: jobTypeDescription,
1302
+ onChange: this.onHandleChange,
1303
+ isRequired: true,
1304
+ isValid: function isValid() {
1305
+ return !_.isEmpty(jobTypeDescription);
1306
+ },
1307
+ showError: function showError() {
1308
+ return showWarnings && _.isEmpty(jobTypeDescription);
1309
+ },
1310
+ alwaysShowLabel: true
1311
+ }));
1312
+ }
1313
+ }, {
1314
+ key: "render",
1315
+ value: function render() {
1316
+ return /*#__PURE__*/React.createElement("div", {
1317
+ style: {
1318
+ minWidth: '100%'
1319
+ }
1320
+ }, /*#__PURE__*/React.createElement("div", null, this.renderJobTypes()), this.renderNewUserTypePopup(), /*#__PURE__*/React.createElement("div", {
1321
+ className: "hub_tidioPadding"
1322
+ }));
1323
+ }
1324
+ }]);
1275
1325
 
1276
- _context2.next = 6;
1277
- return _this.state.editingNote ? maintenanceActions.editNote(_this.state.jobId, _this.state.editingNote, _this.state.noteInput, _this.state.noteAttachments.map(function (a) {
1278
- return {
1279
- Title: a.Title,
1280
- Source: a.Source
1281
- };
1282
- })) : maintenanceActions.addNote(_this.state.jobId, _this.state.noteInput, _this.state.noteAttachments.map(function (a) {
1283
- return {
1284
- Title: a.Title,
1285
- Source: a.Source
1286
- };
1287
- }));
1326
+ return JobTypes;
1327
+ }(Component);
1288
1328
 
1289
- case 6:
1290
- res = _context2.sent;
1329
+ var mapStateToProps$3 = function mapStateToProps(state) {
1330
+ var jobtypes = state.maintenance.jobtypes;
1331
+ var auth = state.auth;
1332
+ return {
1333
+ jobtypes: jobtypes,
1334
+ auth: auth
1335
+ };
1336
+ };
1291
1337
 
1292
- _this.setState({
1293
- job: res.data.job,
1294
- submittingNote: false,
1295
- addNoteOpen: false,
1296
- noteInput: '',
1297
- noteAttachments: [],
1298
- editingNote: null
1299
- }, function () {
1300
- _this.props.jobsLoaded([_this.state.job]);
1301
- });
1338
+ var JobTypes$1 = connect(mapStateToProps$3, {
1339
+ jobTypesLoaded: jobTypesLoaded,
1340
+ jobTypesUpdate: jobTypesUpdate
1341
+ })(withRouter(JobTypes));
1302
1342
 
1303
- _context2.next = 13;
1304
- break;
1343
+ function _createSuper$8(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$8(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1305
1344
 
1306
- case 10:
1307
- _context2.prev = 10;
1308
- _context2.t0 = _context2["catch"](2);
1309
- console.error('onConfirmAddNote', _context2.t0);
1345
+ function _isNativeReflectConstruct$8() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1346
+ var Components$2 = PlussCore.Components,
1347
+ Session$2 = PlussCore.Session;
1310
1348
 
1311
- case 13:
1312
- case "end":
1313
- return _context2.stop();
1314
- }
1315
- }
1316
- }, _callee2, null, [[2, 10]]);
1317
- })));
1349
+ var RequestsHub = /*#__PURE__*/function (_Component) {
1350
+ _inherits(RequestsHub, _Component);
1318
1351
 
1319
- _defineProperty(_assertThisInitialized(_this), "onDeleteNote", function (n) {
1320
- if (!window.confirm('Are you sure you want to delete that note?')) {
1321
- _this.setState({
1322
- noteMenuOpen: null
1323
- });
1352
+ var _super = _createSuper$8(RequestsHub);
1324
1353
 
1325
- return;
1326
- }
1354
+ function RequestsHub(props) {
1355
+ var _this;
1327
1356
 
1328
- maintenanceActions.deleteNote(_this.state.jobId, n.Id);
1357
+ _classCallCheck(this, RequestsHub);
1329
1358
 
1330
- var newNotes = _.filter(_this.state.job.Notes, function (note) {
1331
- return note.Id !== n.Id;
1332
- });
1359
+ _this = _super.call(this, props);
1333
1360
 
1334
- var newJob = _objectSpread$3({}, _this.state.job);
1361
+ _defineProperty(_assertThisInitialized(_this), "setData", function () {
1362
+ var allList = [];
1335
1363
 
1336
- newJob.Notes = newNotes;
1364
+ _this.state.allList.forEach(function (ev) {
1365
+ if (ev != null && !ev.Deleted) allList.push(ev);
1366
+ });
1337
1367
 
1338
- _this.setState({
1339
- job: newJob,
1340
- noteMenuOpen: null
1368
+ var upcoming = _.filter(allList, function (ev) {
1369
+ if (!ev) return false;
1370
+ if (ev.status && ev.status === 'Completed') return false;
1371
+ return true;
1341
1372
  });
1342
- });
1343
1373
 
1344
- _defineProperty(_assertThisInitialized(_this), "onOpenEditNote", function (n) {
1374
+ var completed = _.filter(allList, function (ev) {
1375
+ if (!ev) return false;
1376
+ if (ev.status && ev.status === 'Completed') return true;
1377
+ return false;
1378
+ }); // console.log('setData', upcoming, completed);
1379
+
1380
+
1345
1381
  _this.setState({
1346
- noteAttachments: n.Attachments || [],
1347
- noteInput: n.Note || '',
1348
- addNoteOpen: true,
1349
- editingNote: n.Id,
1350
- noteMenuOpen: null
1382
+ allList: allList,
1383
+ upcoming: upcoming,
1384
+ completed: completed
1351
1385
  });
1352
1386
  });
1353
1387
 
1354
- _defineProperty(_assertThisInitialized(_this), "markSeen", function () {
1355
- var job = _this.state.job;
1356
- var auth = _this.props.auth; // Must have maintenance permission and not the requester
1357
-
1358
- if (!Session$2.validateAccess(auth.site, 'maintenanceTracking', auth)) return;
1359
- if (auth.user.Id === job.userID) return;
1388
+ _defineProperty(_assertThisInitialized(_this), "getData", function () {
1389
+ var auth = _this.props.auth;
1360
1390
 
1361
1391
  _this.setState({
1362
- updating: true
1363
- }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
1364
- var update;
1365
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
1392
+ loadingAll: true
1393
+ }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1394
+ var res;
1395
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1366
1396
  while (1) {
1367
- switch (_context3.prev = _context3.next) {
1397
+ switch (_context.prev = _context.next) {
1368
1398
  case 0:
1369
- _context3.prev = 0;
1370
- update = {
1371
- id: job.id,
1372
- seen: true,
1373
- status: job.status || 'Unassigned'
1374
- };
1375
- _context3.next = 4;
1376
- return maintenanceActions.editJob(update, auth.site);
1399
+ _context.prev = 0;
1400
+ _context.next = 3;
1401
+ return maintenanceActions.getJobs(auth.site);
1377
1402
 
1378
- case 4:
1379
- _context3.next = 11;
1403
+ case 3:
1404
+ res = _context.sent;
1405
+
1406
+ // console.log('getData', res.data);
1407
+ _this.setState({
1408
+ loadingAll: false
1409
+ });
1410
+
1411
+ if (res.data != null && !_.isEmpty(res.data) && res.data[0].site === auth.site) {
1412
+ _this.props.jobsLoaded(res.data);
1413
+ }
1414
+
1415
+ _context.next = 12;
1380
1416
  break;
1381
1417
 
1382
- case 6:
1383
- _context3.prev = 6;
1384
- _context3.t0 = _context3["catch"](0);
1418
+ case 8:
1419
+ _context.prev = 8;
1420
+ _context.t0 = _context["catch"](0);
1421
+ console.error('getData', _context.t0);
1385
1422
 
1386
1423
  _this.setState({
1387
- updating: false
1424
+ loadingAll: false
1388
1425
  });
1389
1426
 
1390
- console.log('markSeen error', _context3.t0);
1391
- alert('Something went wrong with the request. Please try again.');
1392
-
1393
- case 11:
1427
+ case 12:
1394
1428
  case "end":
1395
- return _context3.stop();
1429
+ return _context.stop();
1396
1430
  }
1397
1431
  }
1398
- }, _callee3, null, [[0, 6]]);
1432
+ }, _callee, null, [[0, 8]]);
1399
1433
  })));
1400
1434
  });
1401
1435
 
1402
- _defineProperty(_assertThisInitialized(_this), "getComments", function () {
1403
- reactionActions.getComments(_this.state.jobId, 'maintenancerequest', 0).then(function (res) {
1404
- _this.setState({
1405
- comments: res.data
1406
- });
1407
- });
1436
+ _defineProperty(_assertThisInitialized(_this), "onAddNew", function () {
1437
+ var auth = _this.props.auth;
1438
+
1439
+ if (Session$2.validateAccess(auth.site, 'maintenanceTracking', auth)) {
1440
+ _this.props.history.push("/requestsHub/job");
1441
+ }
1408
1442
  });
1409
1443
 
1410
- _defineProperty(_assertThisInitialized(_this), "onAddComment", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
1411
- var _this$state2, commentInput, jobId, job, comments, res;
1412
-
1413
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
1414
- while (1) {
1415
- switch (_context4.prev = _context4.next) {
1416
- case 0:
1417
- _this$state2 = _this.state, commentInput = _this$state2.commentInput, jobId = _this$state2.jobId, job = _this$state2.job, comments = _this$state2.comments;
1418
- _context4.prev = 1;
1419
-
1420
- _this.setState({
1421
- commentInput: ''
1422
- });
1423
-
1424
- _context4.next = 5;
1425
- return reactionActions.addComment(jobId, 'maintenancerequest', job.title, job.site, commentInput);
1426
-
1427
- case 5:
1428
- res = _context4.sent;
1429
-
1430
- _this.setState({
1431
- comments: [].concat(_toConsumableArray(comments), [res.data])
1432
- });
1433
-
1434
- _context4.next = 12;
1435
- break;
1436
-
1437
- case 9:
1438
- _context4.prev = 9;
1439
- _context4.t0 = _context4["catch"](1);
1440
- console.error('onAddComment', _context4.t0);
1441
-
1442
- case 12:
1443
- case "end":
1444
- return _context4.stop();
1445
- }
1446
- }
1447
- }, _callee4, null, [[1, 9]]);
1448
- })));
1449
-
1450
- _defineProperty(_assertThisInitialized(_this), "onHandleChange", function (event) {
1451
- var stateChange = {};
1452
- stateChange[event.target.getAttribute('id')] = event.target.value;
1453
-
1454
- _this.setState(stateChange);
1444
+ _defineProperty(_assertThisInitialized(_this), "canAddNew", function (isClass) {
1445
+ var auth = _this.props.auth;
1446
+ if (Session$2.validateAccess(auth.site, 'maintenanceTracking', auth)) return isClass ? '' : true;
1447
+ return isClass ? ' hub-sideContent-topButton--hide' : false;
1455
1448
  });
1456
1449
 
1457
- _defineProperty(_assertThisInitialized(_this), "onToggleStatusChanger", function () {
1458
- _this.setState({
1459
- statusChangerOpen: !_this.state.statusChangerOpen
1460
- });
1450
+ _defineProperty(_assertThisInitialized(_this), "getSideBarSectionColour", function (id) {
1451
+ return _this.state.selectedSection === id ? {
1452
+ backgroundColor: '#fff'
1453
+ } : {};
1461
1454
  });
1462
1455
 
1463
- _defineProperty(_assertThisInitialized(_this), "onSelectStatus", /*#__PURE__*/function () {
1464
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(status) {
1465
- var res;
1466
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
1467
- while (1) {
1468
- switch (_context5.prev = _context5.next) {
1469
- case 0:
1470
- _this.setState({
1471
- job: _objectSpread$3(_objectSpread$3({}, _this.state.job), {}, {
1472
- status: status
1473
- }),
1474
- statusChangerOpen: false
1475
- });
1476
-
1477
- _context5.prev = 1;
1478
- _context5.next = 4;
1479
- return maintenanceActions.editJobStatus(_this.state.job.id, status);
1480
-
1481
- case 4:
1482
- res = _context5.sent;
1483
-
1484
- _this.setState({
1485
- job: res.data.job
1486
- }, function () {
1487
- _this.props.jobsLoaded([_this.state.job]);
1488
- });
1489
-
1490
- _context5.next = 11;
1491
- break;
1492
-
1493
- case 8:
1494
- _context5.prev = 8;
1495
- _context5.t0 = _context5["catch"](1);
1496
- console.error('onSelectStatus', _context5.t0);
1497
-
1498
- case 11:
1499
- case "end":
1500
- return _context5.stop();
1501
- }
1502
- }
1503
- }, _callee5, null, [[1, 8]]);
1504
- }));
1505
-
1506
- return function (_x) {
1507
- return _ref5.apply(this, arguments);
1508
- };
1509
- }());
1456
+ _defineProperty(_assertThisInitialized(_this), "renderStats", function (stat, loading) {
1457
+ return loading ? /*#__PURE__*/React.createElement(FontAwesome, {
1458
+ style: styles$4.spinner,
1459
+ name: "spinner fa-pulse fa-fw"
1460
+ }) : stat;
1461
+ });
1510
1462
 
1511
1463
  _this.state = {
1512
- jobId: Helper$2.safeReadParams(props, 'jobId') ? props.match.params.jobId : null,
1513
- job: null,
1514
- showingSelector: false,
1515
- updating: false,
1516
- comments: [],
1517
- commentInput: '',
1518
- loadingComments: false,
1519
- statusChangerOpen: false,
1520
- addNoteOpen: false,
1521
- noteAttachments: [],
1522
- noteInput: ''
1464
+ selectedSection: 'all',
1465
+ location: '',
1466
+ loadingAll: false,
1467
+ loadingSubmissions: false,
1468
+ submissionEntries: [],
1469
+ allList: [],
1470
+ completed: [],
1471
+ upcoming: [],
1472
+ now: moment.utc(),
1473
+ onlyFuture: true,
1474
+ search: ''
1523
1475
  };
1524
1476
  return _this;
1525
1477
  }
1526
1478
 
1527
- _createClass(Job, [{
1528
- key: "UNSAFE_componentWillReceiveProps",
1529
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
1530
- Session$2.checkLoggedIn(this, this.props.auth);
1479
+ _createClass(RequestsHub, [{
1480
+ key: "UNSAFE_componentWillMount",
1481
+ value: function UNSAFE_componentWillMount() {
1482
+ this.updateProps(this.props);
1531
1483
  }
1532
1484
  }, {
1533
1485
  key: "componentDidMount",
1534
1486
  value: function componentDidMount() {
1535
- if (this.state.jobId) {
1536
- this.getJob();
1537
- this.getComments();
1538
- }
1487
+ this.getData();
1539
1488
  }
1540
1489
  }, {
1541
- key: "renderStatusLabel",
1542
- value: function renderStatusLabel() {
1543
- if (!this.state.job.status) return null;
1544
- var auth = this.props.auth;
1545
-
1546
- if (Session$2.validateAccess(auth.site, 'maintenanceTracking', auth)) {
1547
- return /*#__PURE__*/React.createElement("div", {
1548
- className: "statusLabel pointer",
1549
- onClick: this.onToggleStatusChanger,
1550
- style: {
1551
- backgroundColor: StatusTypes[this.state.job.status].color
1552
- }
1553
- }, /*#__PURE__*/React.createElement("span", {
1554
- className: "statusLabel_text"
1555
- }, StatusTypes[this.state.job.status].text), this.renderStatusChanger());
1556
- }
1557
-
1558
- return /*#__PURE__*/React.createElement("div", {
1559
- className: "statusLabel",
1560
- style: {
1561
- backgroundColor: StatusTypes[this.state.job.status].color
1562
- }
1563
- }, /*#__PURE__*/React.createElement("span", {
1564
- className: "statusLabel_text"
1565
- }, StatusTypes[this.state.job.status].text));
1490
+ key: "UNSAFE_componentWillReceiveProps",
1491
+ value: function UNSAFE_componentWillReceiveProps(nextProps) {
1492
+ if (!_.isEqual(this.props.jobs, nextProps.jobs)) this.updateProps(nextProps);
1566
1493
  }
1567
1494
  }, {
1568
- key: "renderNotesButton",
1569
- value: function renderNotesButton() {
1570
- var auth = this.props.auth;
1571
- if (!Session$2.validateAccess(auth.site, 'maintenanceTracking', auth)) return null;
1572
- return /*#__PURE__*/React.createElement("div", {
1573
- className: "statusLabel pointer",
1574
- onClick: this.onOpenAddNote,
1575
- style: {
1576
- backgroundColor: FeatureConfig.env.colourBrandingMain,
1577
- marginLeft: 8
1578
- }
1579
- }, /*#__PURE__*/React.createElement("span", {
1580
- className: "statusLabel_text"
1581
- }, "Add Note"));
1495
+ key: "updateProps",
1496
+ value: function updateProps(props) {
1497
+ this.setState({
1498
+ allList: props.jobs
1499
+ }, this.setData);
1582
1500
  }
1583
1501
  }, {
1584
- key: "renderStatusChanger",
1585
- value: function renderStatusChanger() {
1502
+ key: "renderLeftBar",
1503
+ value: function renderLeftBar() {
1586
1504
  var _this2 = this;
1587
1505
 
1588
- if (!this.state.statusChangerOpen) return null;
1589
- return /*#__PURE__*/React.createElement("div", {
1590
- className: "statusChanger statusChanger-maintenance"
1591
- }, Object.keys(StatusTypes).map(function (statusKey) {
1592
- return /*#__PURE__*/React.createElement("div", {
1593
- key: statusKey,
1594
- className: "statusLabel",
1506
+ var sectionItems = [];
1507
+
1508
+ if (this.canAddNew()) {
1509
+ sectionItems.push({
1510
+ type: 'newButton',
1511
+ text: 'New Request',
1512
+ onClick: this.onAddNew
1513
+ });
1514
+ }
1515
+
1516
+ sectionItems.push({
1517
+ type: 'navItem',
1518
+ text: 'View Requests',
1519
+ icon: 'eye',
1520
+ isFontAwesome: true,
1521
+ selected: this.state.selectedSection === 'all',
1522
+ onClick: function onClick() {
1523
+ _this2.setState({
1524
+ selectedSection: 'all'
1525
+ });
1526
+ }
1527
+ });
1528
+
1529
+ if (Session$2.validateAccess(this.props.auth.site, 'maintenanceTypes', this.props.auth)) {
1530
+ sectionItems.push({
1531
+ type: 'navItem',
1532
+ text: 'Request Types',
1533
+ // icon: 'maintenance2',
1534
+ // isSVG: true,
1535
+ selected: this.state.selectedSection === 'requestTypes',
1595
1536
  onClick: function onClick() {
1596
- return _this2.onSelectStatus(statusKey);
1597
- },
1598
- style: {
1599
- backgroundColor: StatusTypes[statusKey].color
1537
+ _this2.setState({
1538
+ selectedSection: 'requestTypes'
1539
+ });
1600
1540
  }
1601
- }, /*#__PURE__*/React.createElement("span", {
1602
- className: "statusLabel_text"
1603
- }, StatusTypes[statusKey].text));
1604
- }));
1541
+ });
1542
+ }
1543
+
1544
+ return /*#__PURE__*/React.createElement(Components$2.HubSidebar, {
1545
+ sections: [{
1546
+ title: 'Requests',
1547
+ items: sectionItems
1548
+ }]
1549
+ });
1605
1550
  }
1606
1551
  }, {
1607
- key: "renderComment",
1608
- value: function renderComment(c) {
1609
- return /*#__PURE__*/React.createElement("div", {
1610
- key: c.Id,
1611
- className: "comment"
1612
- }, /*#__PURE__*/React.createElement("p", {
1613
- className: "comment_text"
1614
- }, Helper$2.toParagraphed(c.Comment)), /*#__PURE__*/React.createElement("div", {
1615
- className: "comment_bottom"
1616
- }, /*#__PURE__*/React.createElement(Components$2.ProfilePic, {
1617
- className: "comment_profilePic",
1618
- size: 25,
1619
- image: c.User.profilePic
1620
- }), /*#__PURE__*/React.createElement("p", {
1621
- className: "comment_name"
1622
- }, c.User.displayName), /*#__PURE__*/React.createElement("p", {
1623
- className: "comment_time"
1624
- }, moment.utc(c.Timestamp).local().format('D MMM YYYY • h:mma'))));
1552
+ key: "renderRight",
1553
+ value: function renderRight() {
1554
+ if (this.state.selectedSection === 'requestTypes') {
1555
+ return /*#__PURE__*/React.createElement(JobTypes$1, null);
1556
+ }
1557
+
1558
+ return /*#__PURE__*/React.createElement(JobList$1, {
1559
+ source: this.state.allList
1560
+ });
1625
1561
  }
1626
1562
  }, {
1627
- key: "renderCommentSection",
1628
- value: function renderCommentSection() {
1629
- var _this3 = this;
1630
-
1631
- if (this.state.loadingComments) return null;
1563
+ key: "render",
1564
+ value: function render() {
1632
1565
  return /*#__PURE__*/React.createElement("div", {
1633
- className: "padding-60 paddingLeft-20"
1634
- }, /*#__PURE__*/React.createElement("div", {
1635
- className: "newTopBar paddingLeft-40"
1636
- }, /*#__PURE__*/React.createElement(Components$2.Text, {
1637
- type: "formTitleSmall",
1638
- className: "marginBottom-16"
1639
- }, "Comments"), /*#__PURE__*/React.createElement("div", {
1640
- className: "commentSection"
1641
- }, this.state.comments.map(function (c) {
1642
- return _this3.renderComment(c);
1643
- })), /*#__PURE__*/React.createElement("div", {
1644
- className: "commentReply"
1645
- }, /*#__PURE__*/React.createElement("div", {
1646
- className: "commentReply_button".concat(!_.isEmpty(this.state.commentInput) ? ' commentReply_button-active' : ''),
1647
- onClick: this.onAddComment
1648
- }, /*#__PURE__*/React.createElement(FontAwesome, {
1649
- className: "commentReply_icon",
1650
- name: "paper-plane-o"
1651
- })), /*#__PURE__*/React.createElement(Textarea, {
1652
- id: "commentInput",
1653
- placeholder: "Reply here...",
1654
- type: "text",
1655
- className: "commentReply_input",
1656
- value: this.state.commentInput,
1657
- onChange: function onChange(e) {
1658
- return _this3.onHandleChange(e);
1659
- }
1660
- }))));
1661
- }
1662
- }, {
1663
- key: "renderInner",
1664
- value: function renderInner() {
1665
- if (this.state.job == null) return null;
1666
- return /*#__PURE__*/React.createElement("div", {
1667
- style: {
1668
- paddingBottom: 40
1669
- }
1670
- }, /*#__PURE__*/React.createElement("div", {
1671
- className: "padding-60 paddingVertical-40 bottomDivideBorder relative"
1672
- }, /*#__PURE__*/React.createElement(Components$2.Text, {
1673
- type: "formTitleLarge",
1674
- className: "marginBottom-24"
1675
- }, this.state.job.title || 'Request'), /*#__PURE__*/React.createElement("div", {
1676
- className: "marginTop-16"
1677
- }, /*#__PURE__*/React.createElement("div", {
1678
- className: 'fieldLabel'
1679
- }, "Request date"), /*#__PURE__*/React.createElement("div", {
1680
- className: 'fontRegular fontSize-16 text-dark marginTop-5'
1681
- }, moment.utc(this.state.job.createdTime).local().format('D MMM YY'))), /*#__PURE__*/React.createElement("div", {
1682
- className: "marginTop-16"
1683
- }, /*#__PURE__*/React.createElement("div", {
1684
- className: 'fieldLabel'
1685
- }, "Type"), /*#__PURE__*/React.createElement("div", {
1686
- className: 'fontRegular fontSize-16 text-dark marginTop-5'
1687
- }, this.state.job.type)), /*#__PURE__*/React.createElement("div", {
1688
- className: "marginTop-16"
1689
- }, /*#__PURE__*/React.createElement("div", {
1690
- className: 'fieldLabel'
1691
- }, "Location"), /*#__PURE__*/React.createElement("div", {
1692
- className: 'fontRegular fontSize-16 text-dark marginTop-5'
1693
- }, this.state.job.room)), /*#__PURE__*/React.createElement("div", {
1694
- className: "marginTop-16"
1695
- }, /*#__PURE__*/React.createElement("div", {
1696
- className: 'fieldLabel'
1697
- }, "Description ", this.state.job.image ? '- (image supplied)' : ''), /*#__PURE__*/React.createElement("div", {
1698
- className: 'fontRegular fontSize-16 text-dark marginTop-5'
1699
- }, this.state.job.description))), /*#__PURE__*/React.createElement("div", {
1700
- className: "padding-60 paddingVertical-40 bottomDivideBorder"
1701
- }, /*#__PURE__*/React.createElement(Components$2.Text, {
1702
- type: "formTitleSmall",
1703
- className: "marginBottom-16"
1704
- }, "Contact Details"), /*#__PURE__*/React.createElement("div", {
1705
- className: "marginTop-16"
1706
- }, /*#__PURE__*/React.createElement("div", {
1707
- className: 'fieldLabel'
1708
- }, "Name"), /*#__PURE__*/React.createElement("div", {
1709
- className: 'fontRegular fontSize-16 text-dark marginTop-5'
1710
- }, this.state.job.userName)), /*#__PURE__*/React.createElement("div", {
1711
- className: "marginTop-16"
1712
- }, /*#__PURE__*/React.createElement("div", {
1713
- className: 'fieldLabel'
1714
- }, "Contact number"), /*#__PURE__*/React.createElement("div", {
1715
- className: 'fontRegular fontSize-16 text-dark marginTop-5'
1716
- }, _.isEmpty(this.state.job.phone) ? 'No phone provided' : this.state.job.phone)), /*#__PURE__*/React.createElement("div", {
1717
- className: "marginTop-16"
1718
- }, /*#__PURE__*/React.createElement("div", {
1719
- className: 'fieldLabel'
1720
- }, "Should person be home?"), /*#__PURE__*/React.createElement("div", {
1721
- className: 'fontRegular fontSize-16 text-dark marginTop-5'
1722
- }, this.state.job.isHome ? 'Yes' : 'No')), this.state.job.isHome && this.state.job.homeText && /*#__PURE__*/React.createElement("div", {
1723
- className: "marginTop-16"
1724
- }, /*#__PURE__*/React.createElement("div", {
1725
- className: 'fieldLabel'
1726
- }, "When"), /*#__PURE__*/React.createElement("div", {
1727
- className: 'fontRegular fontSize-16 text-dark marginTop-5'
1728
- }, this.state.job.homeText))), (this.state.job.image || this.state.job.images) && /*#__PURE__*/React.createElement("div", {
1729
- className: "padding-60 paddingVertical-40 bottomDivideBorder"
1730
- }, /*#__PURE__*/React.createElement(Components$2.Text, {
1731
- type: "formTitleSmall",
1732
- className: "marginBottom-16"
1733
- }, "Image"), /*#__PURE__*/React.createElement("div", {
1734
- style: {
1735
- marginTop: 16,
1736
- height: 180,
1737
- width: 260,
1738
- borderRadius: 4,
1739
- border: '1px solid #aaa',
1740
- backgroundColor: '#ddd',
1741
- backgroundImage: "url(".concat(this.state.job.thumbnail, ")"),
1742
- backgroundPosition: 'center'
1743
- }
1744
- })), this.renderCommentSection());
1566
+ className: "hub-wrapperContainer"
1567
+ }, this.renderLeftBar(), /*#__PURE__*/React.createElement("div", {
1568
+ className: "hub-headerContentWrapper"
1569
+ }, /*#__PURE__*/React.createElement(Components$2.Header, null), /*#__PURE__*/React.createElement("div", {
1570
+ className: "hub-contentWrapper"
1571
+ }, this.renderRight())));
1745
1572
  }
1746
- }, {
1747
- key: "renderHistoryEntry",
1748
- value: function renderHistoryEntry(e, i) {
1749
- var job = this.state.job;
1750
- var entryToUse = e || {
1751
- timestamp: job.createdTime,
1752
- status: 'Unassigned',
1753
- user: {
1754
- displayName: job.userName,
1755
- id: job.userID,
1756
- profilePic: job.userProfilePic
1573
+ }]);
1574
+
1575
+ return RequestsHub;
1576
+ }(Component);
1577
+
1578
+ var styles$4 = {
1579
+ sideBarTitleSection: {
1580
+ lineHeight: '40px',
1581
+ marginTop: 30,
1582
+ marginBottom: 30,
1583
+ paddingLeft: 24,
1584
+ paddingRight: 24
1585
+ },
1586
+ sideBarSection: {
1587
+ weight: '100%',
1588
+ minWidth: 200,
1589
+ padding: 32,
1590
+ paddingLeft: 24,
1591
+ cursor: 'pointer',
1592
+ display: 'flex',
1593
+ flexDirection: 'column',
1594
+ justifyContent: 'center'
1595
+ },
1596
+ spinner: {
1597
+ fontSize: 32,
1598
+ color: FeatureConfig.env.colourBrandingOff
1599
+ }
1600
+ };
1601
+
1602
+ var mapStateToProps$2 = function mapStateToProps(state) {
1603
+ var jobs = state.maintenance.jobs;
1604
+ var auth = state.auth;
1605
+ return {
1606
+ jobs: jobs,
1607
+ auth: auth
1608
+ };
1609
+ };
1610
+
1611
+ var RequestsHub$1 = connect(mapStateToProps$2, {
1612
+ jobsLoaded: jobsLoaded
1613
+ })(withRouter(RequestsHub));
1614
+
1615
+ function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1616
+
1617
+ function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1618
+
1619
+ function _createSuper$7(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$7(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1620
+
1621
+ function _isNativeReflectConstruct$7() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1622
+ var Apis = PlussCore.Apis,
1623
+ Helper$1 = PlussCore.Helper,
1624
+ Session$1 = PlussCore.Session,
1625
+ Colours = PlussCore.Colours,
1626
+ Components$1 = PlussCore.Components;
1627
+
1628
+ var Job = /*#__PURE__*/function (_Component) {
1629
+ _inherits(Job, _Component);
1630
+
1631
+ var _super = _createSuper$7(Job);
1632
+
1633
+ function Job(props) {
1634
+ var _this;
1635
+
1636
+ _classCallCheck(this, Job);
1637
+
1638
+ _this = _super.call(this, props);
1639
+
1640
+ _defineProperty(_assertThisInitialized(_this), "getJob", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1641
+ var res;
1642
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1643
+ while (1) {
1644
+ switch (_context.prev = _context.next) {
1645
+ case 0:
1646
+ _context.prev = 0;
1647
+ _context.next = 3;
1648
+ return maintenanceActions.getJob(_this.props.auth.site, _this.state.jobId);
1649
+
1650
+ case 3:
1651
+ res = _context.sent;
1652
+
1653
+ _this.setState({
1654
+ updating: false
1655
+ });
1656
+
1657
+ res.data.location = res.data.site;
1658
+
1659
+ _this.setJob(res.data);
1660
+
1661
+ _context.next = 12;
1662
+ break;
1663
+
1664
+ case 9:
1665
+ _context.prev = 9;
1666
+ _context.t0 = _context["catch"](0);
1667
+ console.error('getJob', _context.t0);
1668
+
1669
+ case 12:
1670
+ case "end":
1671
+ return _context.stop();
1672
+ }
1757
1673
  }
1674
+ }, _callee, null, [[0, 9]]);
1675
+ })));
1676
+
1677
+ _defineProperty(_assertThisInitialized(_this), "setJob", function (job) {
1678
+ job.typeIcon = job.type === 'General' ? 'wrench' : 'tree';
1679
+ job.typeColour = job.type === 'General' ? '#666' : 'green';
1680
+
1681
+ if (_.isEmpty(job.lastActivity)) {
1682
+ job.lastActivity = '-- --';
1683
+ job.noActivity = true;
1684
+ }
1685
+
1686
+ if (_.isEmpty(job.status)) {
1687
+ job.status = 'Unassigned';
1688
+ job.notStatus = true;
1689
+ }
1690
+
1691
+ if (_.isEmpty(job.audience)) {
1692
+ job.audience = [{
1693
+ displayName: 'Unassigned',
1694
+ isEmpty: true
1695
+ }];
1696
+ }
1697
+
1698
+ var needToMarkSeen = false;
1699
+
1700
+ if (!job.seen) {
1701
+ job.seen = true;
1702
+ needToMarkSeen = true;
1703
+ }
1704
+
1705
+ _this.setState({
1706
+ job: job
1707
+ }, function () {
1708
+ if (needToMarkSeen) _this.markSeen();
1709
+ });
1710
+
1711
+ _this.props.jobsLoaded([job]);
1712
+ });
1713
+
1714
+ _defineProperty(_assertThisInitialized(_this), "editJob", function () {});
1715
+
1716
+ _defineProperty(_assertThisInitialized(_this), "isReadyToSaveNote", function () {
1717
+ var _this$state = _this.state,
1718
+ noteAttachments = _this$state.noteAttachments,
1719
+ noteInput = _this$state.noteInput;
1720
+ if (_.some(noteAttachments, function (n) {
1721
+ return n.Uploading;
1722
+ })) return false;
1723
+ return !_.isEmpty(noteInput) || !_.isEmpty(noteAttachments);
1724
+ });
1725
+
1726
+ _defineProperty(_assertThisInitialized(_this), "onOpenAddNote", function () {
1727
+ _this.setState({
1728
+ addNoteOpen: true,
1729
+ editingNote: null
1730
+ });
1731
+ });
1732
+
1733
+ _defineProperty(_assertThisInitialized(_this), "onCloseAddNote", function () {
1734
+ var newState = {
1735
+ addNoteOpen: false,
1736
+ editingNote: null
1758
1737
  };
1759
- return /*#__PURE__*/React.createElement("div", {
1760
- className: "ticketHistoryEntry",
1761
- key: i
1762
- }, /*#__PURE__*/React.createElement("p", {
1763
- className: "ticketHistoryEntry_timestamp"
1764
- }, moment.utc(entryToUse.timestamp).local().format('D MMM YYYY h:mma')), /*#__PURE__*/React.createElement("div", {
1765
- className: "statusLabel statusLabel-large statusLabel-full",
1766
- style: {
1767
- backgroundColor: StatusTypes[entryToUse.status].color
1768
- }
1769
- }, /*#__PURE__*/React.createElement("span", {
1770
- className: "statusLabel_text"
1771
- }, e ? "Marked as ".concat(StatusTypes[entryToUse.status].text) : 'Job opened')));
1772
- }
1773
- }, {
1774
- key: "renderNote",
1775
- value: function renderNote(note, index) {
1776
- var _this4 = this;
1777
1738
 
1778
- return /*#__PURE__*/React.createElement("div", {
1779
- className: "ticketHistoryEntry",
1780
- key: index
1781
- }, /*#__PURE__*/React.createElement("p", {
1782
- className: "ticketHistoryEntry_timestamp"
1783
- }, moment.utc(note.Timestamp).local().format('D MMM YYYY h:mma')), /*#__PURE__*/React.createElement("div", {
1784
- className: "statusLabel statusLabel-large statusLabel-full",
1785
- style: {
1786
- backgroundColor: '#6e79c5'
1787
- }
1788
- }, /*#__PURE__*/React.createElement("span", {
1789
- className: "statusLabel_text"
1790
- }, "Staff Notes")), /*#__PURE__*/React.createElement("div", {
1791
- className: "maintenanceNote"
1792
- }, /*#__PURE__*/React.createElement("div", {
1793
- className: "maintenanceNote_top"
1794
- }, this.props.auth && this.props.auth.user && this.props.auth.user.Id === note.User.id && /*#__PURE__*/React.createElement(Components$2.SVGIcon, {
1795
- colour: Colours.COLOUR_DUSK_LIGHT,
1796
- icon: "more15",
1797
- className: "maintenanceNote_moreIcon",
1798
- onClick: function onClick() {
1799
- return _this4.onOpenNoteMenu(index);
1800
- }
1801
- }), /*#__PURE__*/React.createElement("p", {
1802
- className: "maintenanceNote_name"
1803
- }, note.User.displayName), this.state.noteMenuOpen === index && /*#__PURE__*/React.createElement(Components$2.MoreMenu, {
1804
- options: [{
1805
- key: 'edit',
1806
- text: 'Edit',
1807
- onPress: function onPress() {
1808
- return _this4.onOpenEditNote(note);
1809
- }
1810
- }, {
1811
- key: 'delete',
1812
- text: 'Delete',
1813
- onPress: function onPress() {
1814
- return _this4.onDeleteNote(note);
1815
- }
1816
- }]
1817
- })), /*#__PURE__*/React.createElement("p", {
1818
- className: "maintenanceNote_text"
1819
- }, Helper$2.toParagraphed(note.Note)), note.Attachments.map(function (a, i) {
1820
- return _this4.renderAttachment(a, i);
1821
- })));
1822
- }
1823
- }, {
1824
- key: "renderOverview",
1825
- value: function renderOverview() {
1826
- var _this5 = this;
1739
+ if (!!_this.state.editingNote) {
1740
+ newState.noteInput = '';
1741
+ newState.noteAttachments = [];
1742
+ }
1743
+
1744
+ _this.setState(newState);
1745
+ });
1746
+
1747
+ _defineProperty(_assertThisInitialized(_this), "onOpenNoteMenu", function (index) {
1748
+ if (_this.state.noteMenuOpen === index) {
1749
+ _this.setState({
1750
+ noteMenuOpen: null
1751
+ });
1752
+ } else {
1753
+ _this.setState({
1754
+ noteMenuOpen: index
1755
+ });
1756
+ }
1757
+ });
1758
+
1759
+ _defineProperty(_assertThisInitialized(_this), "onHandlePDFFileChange", function (event) {
1760
+ var file = event.target.files[0];
1761
+ if (!file || _this.state.uploadingNoteAttachment) return;
1762
+
1763
+ var noteAttachments = _toConsumableArray(_this.state.noteAttachments);
1764
+
1765
+ var newAttachment = {
1766
+ Uploading: true,
1767
+ Title: file.name
1768
+ };
1769
+ noteAttachments.push(newAttachment);
1770
+
1771
+ _this.setState({
1772
+ noteAttachments: noteAttachments
1773
+ });
1774
+
1775
+ Apis.fileActions.uploadMediaAsync(file, file.name).then(function (fileRes) {
1776
+ newAttachment.Source = fileRes;
1777
+ newAttachment.Uploading = false;
1778
+
1779
+ _this.setState({
1780
+ noteAttachments: _toConsumableArray(_this.state.noteAttachments)
1781
+ });
1782
+ }).catch(function (uploadErrorRes) {
1783
+ console.log(uploadErrorRes);
1784
+ newAttachment.Uploading = false;
1785
+
1786
+ _this.setState({
1787
+ noteAttachments: _toConsumableArray(_this.state.noteAttachments)
1788
+ });
1789
+ });
1790
+ event.target.value = '';
1791
+ });
1792
+
1793
+ _defineProperty(_assertThisInitialized(_this), "onRemoveAttachment", function (a) {
1794
+ var index = _this.state.noteAttachments.indexOf(a);
1795
+
1796
+ if (index > -1) {
1797
+ var newAttachments = _toConsumableArray(_this.state.noteAttachments);
1798
+
1799
+ newAttachments.splice(index, 1);
1800
+
1801
+ _this.setState({
1802
+ noteAttachments: newAttachments
1803
+ });
1804
+ }
1805
+ });
1806
+
1807
+ _defineProperty(_assertThisInitialized(_this), "onConfirmAddNote", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
1808
+ var res;
1809
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1810
+ while (1) {
1811
+ switch (_context2.prev = _context2.next) {
1812
+ case 0:
1813
+ if (_this.isReadyToSaveNote()) {
1814
+ _context2.next = 2;
1815
+ break;
1816
+ }
1817
+
1818
+ return _context2.abrupt("return");
1819
+
1820
+ case 2:
1821
+ _context2.prev = 2;
1822
+
1823
+ _this.setState({
1824
+ submittingNote: true
1825
+ });
1826
+
1827
+ _context2.next = 6;
1828
+ return _this.state.editingNote ? maintenanceActions.editNote(_this.state.jobId, _this.state.editingNote, _this.state.noteInput, _this.state.noteAttachments.map(function (a) {
1829
+ return {
1830
+ Title: a.Title,
1831
+ Source: a.Source
1832
+ };
1833
+ })) : maintenanceActions.addNote(_this.state.jobId, _this.state.noteInput, _this.state.noteAttachments.map(function (a) {
1834
+ return {
1835
+ Title: a.Title,
1836
+ Source: a.Source
1837
+ };
1838
+ }));
1827
1839
 
1828
- var job = this.state.job;
1829
- if (!job || !job.history) return null;
1840
+ case 6:
1841
+ res = _context2.sent;
1830
1842
 
1831
- var source = _.sortBy([].concat(_toConsumableArray(job.history.map(function (e) {
1832
- return _objectSpread$3(_objectSpread$3({}, e), {}, {
1833
- EntryType: 'status'
1834
- });
1835
- })), _toConsumableArray((job.Notes || []).map(function (e) {
1836
- return _objectSpread$3(_objectSpread$3({}, e), {}, {
1837
- timestamp: e.Timestamp,
1838
- EntryType: 'note'
1839
- });
1840
- }))), 'timestamp');
1843
+ _this.setState({
1844
+ job: res.data.job,
1845
+ submittingNote: false,
1846
+ addNoteOpen: false,
1847
+ noteInput: '',
1848
+ noteAttachments: [],
1849
+ editingNote: null
1850
+ }, function () {
1851
+ _this.props.jobsLoaded([_this.state.job]);
1852
+ });
1841
1853
 
1842
- return /*#__PURE__*/React.createElement("div", {
1843
- className: "padding-32 paddingVertical-40 bottomDivideBorder relative"
1844
- }, /*#__PURE__*/React.createElement("div", {
1845
- className: "newTopBar clearfix flex flex-reverse"
1846
- }, this.renderNotesButton(), this.renderStatusLabel(), /*#__PURE__*/React.createElement(Components$2.Text, {
1847
- type: "formTitleSmall",
1848
- className: "flex-1"
1849
- }, "Status History")), this.renderHistoryEntry(null, -1), _.map(source, function (e, i) {
1850
- switch (e.EntryType) {
1851
- case 'status':
1852
- return _this5.renderHistoryEntry(e, i);
1854
+ _context2.next = 13;
1855
+ break;
1853
1856
 
1854
- case 'note':
1855
- return _this5.renderNote(e, i);
1856
- }
1857
- }));
1858
- }
1859
- }, {
1860
- key: "renderButtons",
1861
- value: function renderButtons() {
1862
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Components$2.Button, {
1863
- inline: true,
1864
- buttonType: "tertiary",
1865
- onClick: function onClick() {
1866
- window.history.back();
1867
- },
1868
- isActive: true,
1869
- style: {
1870
- marginRight: 16
1857
+ case 10:
1858
+ _context2.prev = 10;
1859
+ _context2.t0 = _context2["catch"](2);
1860
+ console.error('onConfirmAddNote', _context2.t0);
1861
+
1862
+ case 13:
1863
+ case "end":
1864
+ return _context2.stop();
1865
+ }
1871
1866
  }
1872
- }, "Back"), Session$2.validateAccess(this.props.auth.site, 'maintenanceTracking', this.props.auth) && !_.isEmpty(this.state.job) && /*#__PURE__*/React.createElement(Link, {
1873
- to: "/requestsHub/job/".concat(this.state.jobId)
1874
- }, /*#__PURE__*/React.createElement(Components$2.Button, {
1875
- inline: true,
1876
- style: {
1877
- marginRight: 25
1878
- },
1879
- buttonType: "outlined",
1880
- isActive: true,
1881
- onClick: this.editJob
1882
- }, "Edit Details")));
1883
- }
1884
- }, {
1885
- key: "renderAttachment",
1886
- value: function renderAttachment(attachment, index, onRemove) {
1887
- if (!attachment) return null;
1888
- return /*#__PURE__*/React.createElement(Components$2.Attachment, {
1889
- key: index,
1890
- uploading: attachment.Uploading,
1891
- source: attachment.Source,
1892
- title: attachment.Title,
1893
- onRemove: onRemove ? function () {
1894
- return onRemove(attachment);
1895
- } : undefined
1896
- });
1897
- }
1898
- }, {
1899
- key: "renderAddNotePopup",
1900
- value: function renderAddNotePopup() {
1901
- var _this6 = this;
1867
+ }, _callee2, null, [[2, 10]]);
1868
+ })));
1902
1869
 
1903
- if (!this.state.addNoteOpen) return null;
1870
+ _defineProperty(_assertThisInitialized(_this), "onDeleteNote", function (n) {
1871
+ if (!window.confirm('Are you sure you want to delete that note?')) {
1872
+ _this.setState({
1873
+ noteMenuOpen: null
1874
+ });
1904
1875
 
1905
- if (this.state.submittingNote) {
1906
- return /*#__PURE__*/React.createElement(Components$2.Popup, {
1907
- title: "Saving Note",
1908
- maxWidth: 600,
1909
- hasPadding: true
1910
- }, /*#__PURE__*/React.createElement("div", {
1911
- className: "flex flex-center-row"
1912
- }, /*#__PURE__*/React.createElement(FontAwesome, {
1913
- className: "spinner",
1914
- name: "spinner fa-pulse fa-fw"
1915
- })));
1876
+ return;
1916
1877
  }
1917
1878
 
1918
- return /*#__PURE__*/React.createElement(Components$2.Popup, {
1919
- title: "".concat(this.state.editingNote ? 'Edit' : 'Add', " Note"),
1920
- onClose: this.onCloseAddNote,
1921
- maxWidth: 600,
1922
- hasPadding: true,
1923
- buttons: [{
1924
- type: 'primary',
1925
- onClick: this.onConfirmAddNote,
1926
- isActive: this.isReadyToSaveNote(),
1927
- text: 'Save'
1928
- }, {
1929
- type: 'tertiary',
1930
- onClick: this.onCloseAddNote,
1931
- isActive: true,
1932
- text: 'Cancel'
1933
- }]
1934
- }, /*#__PURE__*/React.createElement(Components$2.GenericInput, {
1935
- id: "noteInput",
1936
- type: "textarea",
1937
- componentClass: "textarea",
1938
- value: this.state.noteInput,
1939
- placeholder: "Enter note",
1940
- onChange: function onChange(e) {
1941
- return _this6.onHandleChange(e);
1942
- },
1943
- inputStyle: {
1944
- width: 400
1945
- }
1946
- }), /*#__PURE__*/React.createElement(Components$2.Text, {
1947
- type: "h5"
1948
- }, "Attachments"), this.state.noteAttachments.map(function (a, i) {
1949
- return _this6.renderAttachment(a, i, _this6.onRemoveAttachment);
1950
- }), /*#__PURE__*/React.createElement("input", {
1951
- ref: function ref(input) {
1952
- return _this6.attachmentInput = input;
1953
- },
1954
- id: "attachmentInput",
1955
- type: "file",
1956
- className: "fileInput",
1957
- onChange: function onChange(e) {
1958
- return _this6.onHandlePDFFileChange(e);
1959
- },
1960
- accept: "application/pdf"
1961
- }), /*#__PURE__*/React.createElement("div", {
1962
- className: "iconTextButton",
1963
- onClick: function onClick() {
1964
- _this6.attachmentInput.click();
1965
- }
1966
- }, /*#__PURE__*/React.createElement(FontAwesome, {
1967
- className: "iconTextButton_icon",
1968
- name: "paperclip"
1969
- }), /*#__PURE__*/React.createElement("p", {
1970
- className: "iconTextButton_text"
1971
- }, "Add Attachment")));
1972
- }
1973
- }, {
1974
- key: "render",
1975
- value: function render() {
1976
- return /*#__PURE__*/React.createElement(Components$2.OverlayPage, null, this.renderAddNotePopup(), /*#__PURE__*/React.createElement(Components$2.OverlayPageContents, null, /*#__PURE__*/React.createElement(Components$2.OverlayPageSection, {
1977
- className: "pageSectionWrapper--newPopup"
1978
- }, this.renderInner()), /*#__PURE__*/React.createElement(Components$2.OverlayPageSection, {
1979
- className: "pageSectionWrapper--newPopupSide pageSectionWrapper--newPopupSide-fixedWidth"
1980
- }, this.renderOverview())), /*#__PURE__*/React.createElement(Components$2.OverlayPageBottomButtons, null, this.renderButtons()));
1981
- }
1982
- }]);
1983
-
1984
- return Job;
1985
- }(Component);
1879
+ maintenanceActions.deleteNote(_this.state.jobId, n.Id);
1986
1880
 
1987
- var mapStateToProps$2 = function mapStateToProps(state) {
1988
- var auth = state.auth;
1989
- return {
1990
- auth: auth
1991
- };
1992
- };
1881
+ var newNotes = _.filter(_this.state.job.Notes, function (note) {
1882
+ return note.Id !== n.Id;
1883
+ });
1993
1884
 
1994
- var Job$1 = connect(mapStateToProps$2, {
1995
- jobsLoaded: jobsLoaded
1996
- })(withRouter(Job));
1885
+ var newJob = _objectSpread$3({}, _this.state.job);
1997
1886
 
1998
- function _createSuper$7(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$7(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1887
+ newJob.Notes = newNotes;
1999
1888
 
2000
- function _isNativeReflectConstruct$7() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2001
- var Actions = PlussCore.Actions,
2002
- Components$1 = PlussCore.Components,
2003
- Helper$1 = PlussCore.Helper,
2004
- Session$1 = PlussCore.Session;
1889
+ _this.setState({
1890
+ job: newJob,
1891
+ noteMenuOpen: null
1892
+ });
1893
+ });
2005
1894
 
2006
- var AddJob = /*#__PURE__*/function (_Component) {
2007
- _inherits(AddJob, _Component);
1895
+ _defineProperty(_assertThisInitialized(_this), "onOpenEditNote", function (n) {
1896
+ _this.setState({
1897
+ noteAttachments: n.Attachments || [],
1898
+ noteInput: n.Note || '',
1899
+ addNoteOpen: true,
1900
+ editingNote: n.Id,
1901
+ noteMenuOpen: null
1902
+ });
1903
+ });
2008
1904
 
2009
- var _super = _createSuper$7(AddJob);
1905
+ _defineProperty(_assertThisInitialized(_this), "markSeen", function () {
1906
+ var job = _this.state.job;
1907
+ var auth = _this.props.auth; // Must have maintenance permission and not the requester
2010
1908
 
2011
- function AddJob(props) {
2012
- var _this;
1909
+ if (!Session$1.validateAccess(auth.site, 'maintenanceTracking', auth)) return;
1910
+ if (auth.user.Id === job.userID) return;
2013
1911
 
2014
- _classCallCheck(this, AddJob);
1912
+ _this.setState({
1913
+ updating: true
1914
+ }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
1915
+ var update;
1916
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
1917
+ while (1) {
1918
+ switch (_context3.prev = _context3.next) {
1919
+ case 0:
1920
+ _context3.prev = 0;
1921
+ update = {
1922
+ id: job.id,
1923
+ seen: true,
1924
+ status: job.status || 'Unassigned'
1925
+ };
1926
+ _context3.next = 4;
1927
+ return maintenanceActions.editJob(update, auth.site);
2015
1928
 
2016
- _this = _super.call(this, props);
1929
+ case 4:
1930
+ _context3.next = 11;
1931
+ break;
2017
1932
 
2018
- _defineProperty(_assertThisInitialized(_this), "getJob", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
2019
- var res;
2020
- return _regeneratorRuntime.wrap(function _callee$(_context) {
2021
- while (1) {
2022
- switch (_context.prev = _context.next) {
2023
- case 0:
2024
- _context.prev = 0;
2025
- _context.next = 3;
2026
- return maintenanceActions.getJob(_this.props.auth.site, _this.state.jobId);
1933
+ case 6:
1934
+ _context3.prev = 6;
1935
+ _context3.t0 = _context3["catch"](0);
2027
1936
 
2028
- case 3:
2029
- res = _context.sent;
2030
- res.data.location = res.data.site;
1937
+ _this.setState({
1938
+ updating: false
1939
+ });
2031
1940
 
2032
- _this.setState(res.data);
1941
+ console.log('markSeen error', _context3.t0);
1942
+ alert('Something went wrong with the request. Please try again.');
2033
1943
 
2034
- _context.next = 11;
2035
- break;
1944
+ case 11:
1945
+ case "end":
1946
+ return _context3.stop();
1947
+ }
1948
+ }
1949
+ }, _callee3, null, [[0, 6]]);
1950
+ })));
1951
+ });
2036
1952
 
2037
- case 8:
2038
- _context.prev = 8;
2039
- _context.t0 = _context["catch"](0);
2040
- console.error('getJob', _context.t0);
1953
+ _defineProperty(_assertThisInitialized(_this), "getComments", function () {
1954
+ reactionActions.getComments(_this.state.jobId, 'maintenancerequest', 0).then(function (res) {
1955
+ _this.setState({
1956
+ comments: res.data
1957
+ });
1958
+ });
1959
+ });
2041
1960
 
2042
- case 11:
2043
- case "end":
2044
- return _context.stop();
2045
- }
2046
- }
2047
- }, _callee, null, [[0, 8]]);
2048
- })));
1961
+ _defineProperty(_assertThisInitialized(_this), "onAddComment", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
1962
+ var _this$state2, commentInput, jobId, job, comments, res;
2049
1963
 
2050
- _defineProperty(_assertThisInitialized(_this), "getJobTypes", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
2051
- var res;
2052
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1964
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
2053
1965
  while (1) {
2054
- switch (_context2.prev = _context2.next) {
1966
+ switch (_context4.prev = _context4.next) {
2055
1967
  case 0:
2056
- _context2.prev = 0;
2057
- _context2.next = 3;
2058
- return maintenanceActions.getJobTypes(_this.props.auth.site);
2059
-
2060
- case 3:
2061
- res = _context2.sent;
1968
+ _this$state2 = _this.state, commentInput = _this$state2.commentInput, jobId = _this$state2.jobId, job = _this$state2.job, comments = _this$state2.comments;
1969
+ _context4.prev = 1;
2062
1970
 
2063
1971
  _this.setState({
2064
- types: res.data
1972
+ commentInput: ''
2065
1973
  });
2066
1974
 
2067
- _this.getDefaultJob();
1975
+ _context4.next = 5;
1976
+ return reactionActions.addComment(jobId, 'maintenancerequest', job.title, job.site, commentInput);
2068
1977
 
2069
- _context2.next = 11;
1978
+ case 5:
1979
+ res = _context4.sent;
1980
+
1981
+ _this.setState({
1982
+ comments: [].concat(_toConsumableArray(comments), [res.data])
1983
+ });
1984
+
1985
+ _context4.next = 12;
2070
1986
  break;
2071
1987
 
2072
- case 8:
2073
- _context2.prev = 8;
2074
- _context2.t0 = _context2["catch"](0);
2075
- console.error('getJobTypes', _context2.t0);
1988
+ case 9:
1989
+ _context4.prev = 9;
1990
+ _context4.t0 = _context4["catch"](1);
1991
+ console.error('onAddComment', _context4.t0);
2076
1992
 
2077
- case 11:
1993
+ case 12:
2078
1994
  case "end":
2079
- return _context2.stop();
1995
+ return _context4.stop();
2080
1996
  }
2081
1997
  }
2082
- }, _callee2, null, [[0, 8]]);
1998
+ }, _callee4, null, [[1, 9]]);
2083
1999
  })));
2084
2000
 
2085
- _defineProperty(_assertThisInitialized(_this), "getDefaultJob", function () {
2086
- if (_this.state.types.length !== 0 && _this.state.jobId == null) {
2087
- _this.setState({
2088
- type: _this.state.types[0].typeName
2089
- });
2090
- }
2091
- });
2092
-
2093
- _defineProperty(_assertThisInitialized(_this), "onSelectType", function (key, e) {
2094
- _this.setState({
2095
- type: key
2096
- });
2097
- });
2098
-
2099
2001
  _defineProperty(_assertThisInitialized(_this), "onHandleChange", function (event) {
2100
2002
  var stateChange = {};
2101
2003
  stateChange[event.target.getAttribute('id')] = event.target.value;
@@ -2103,348 +2005,534 @@ var AddJob = /*#__PURE__*/function (_Component) {
2103
2005
  _this.setState(stateChange);
2104
2006
  });
2105
2007
 
2106
- _defineProperty(_assertThisInitialized(_this), "onSave", function () {
2008
+ _defineProperty(_assertThisInitialized(_this), "onToggleStatusChanger", function () {
2107
2009
  _this.setState({
2108
- showWarnings: false
2010
+ statusChangerOpen: !_this.state.statusChangerOpen
2109
2011
  });
2012
+ });
2110
2013
 
2111
- if (!_this.validateForm()) {
2112
- _this.setState({
2113
- showWarnings: true
2114
- });
2115
-
2116
- return;
2117
- }
2118
-
2119
- if (_this.state.updating) return;
2014
+ _defineProperty(_assertThisInitialized(_this), "onSelectStatus", /*#__PURE__*/function () {
2015
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(status) {
2016
+ var res;
2017
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
2018
+ while (1) {
2019
+ switch (_context5.prev = _context5.next) {
2020
+ case 0:
2021
+ _this.setState({
2022
+ job: _objectSpread$3(_objectSpread$3({}, _this.state.job), {}, {
2023
+ status: status
2024
+ }),
2025
+ statusChangerOpen: false
2026
+ });
2120
2027
 
2121
- _this.setState({
2122
- updating: true
2123
- });
2028
+ _context5.prev = 1;
2029
+ _context5.next = 4;
2030
+ return maintenanceActions.editJobStatus(_this.state.job.id, status);
2124
2031
 
2125
- var job = {
2126
- id: _this.state.id,
2127
- userID: _this.state.userID,
2128
- userName: _this.state.userName,
2129
- room: _this.state.room,
2130
- phone: _this.state.phone,
2131
- location: _this.state.location,
2132
- title: _this.state.title,
2133
- description: _this.state.description,
2134
- isHome: _this.state.isHome,
2135
- homeText: _this.state.homeText,
2136
- type: _this.state.type,
2137
- date: null,
2138
- image: _this.state.image
2139
- };
2032
+ case 4:
2033
+ res = _context5.sent;
2140
2034
 
2141
- if (_this.state.id != null) {
2142
- maintenanceActions.editJob(job, _this.props.auth.site).then(function (res) {
2143
- _this.setState({
2144
- success: true,
2145
- updating: false
2146
- });
2035
+ _this.setState({
2036
+ job: res.data.job
2037
+ }, function () {
2038
+ _this.props.jobsLoaded([_this.state.job]);
2039
+ });
2147
2040
 
2148
- _this.props.jobsLoaded([job]);
2149
- }).catch(function (res) {
2150
- _this.setState({
2151
- updating: false
2152
- });
2041
+ _context5.next = 11;
2042
+ break;
2153
2043
 
2154
- alert('Something went wrong with the request. Please try again.');
2155
- });
2156
- } else {
2157
- // Create New Job
2158
- job.userID = 'undefined';
2159
- maintenanceActions.createJob(job).then(function (res) {
2160
- _this.setState({
2161
- success: true,
2162
- updating: false
2163
- });
2044
+ case 8:
2045
+ _context5.prev = 8;
2046
+ _context5.t0 = _context5["catch"](1);
2047
+ console.error('onSelectStatus', _context5.t0);
2164
2048
 
2165
- _this.props.jobsUpdate(_this.props.auth.site);
2166
- }).catch(function (res) {
2167
- _this.setState({
2168
- updating: false
2169
- });
2049
+ case 11:
2050
+ case "end":
2051
+ return _context5.stop();
2052
+ }
2053
+ }
2054
+ }, _callee5, null, [[1, 8]]);
2055
+ }));
2170
2056
 
2171
- alert('Something went wrong with the request. Please try again.');
2172
- });
2173
- }
2174
- });
2057
+ return function (_x) {
2058
+ return _ref5.apply(this, arguments);
2059
+ };
2060
+ }());
2175
2061
 
2176
2062
  _this.state = {
2177
- jobId: Helper$1.safeReadParams(_this.props, 'jobId') ? _this.props.match.params.jobId : null,
2063
+ jobId: Helper$1.safeReadParams(props, 'jobId') ? props.match.params.jobId : null,
2178
2064
  job: null,
2179
2065
  showingSelector: false,
2180
2066
  updating: false,
2181
- connected: false,
2182
- types: [],
2183
- id: null,
2184
- userID: '',
2185
- userName: '',
2186
- room: '',
2187
- phone: '',
2188
- location: _this.props.auth.site,
2189
- title: '',
2190
- description: '',
2191
- isHome: false,
2192
- homeText: '',
2193
- type: 'General',
2194
- image: null,
2195
- thumbnail: null,
2196
- showWarnings: false,
2197
- success: false
2067
+ comments: [],
2068
+ commentInput: '',
2069
+ loadingComments: false,
2070
+ statusChangerOpen: false,
2071
+ addNoteOpen: false,
2072
+ noteAttachments: [],
2073
+ noteInput: ''
2198
2074
  };
2199
2075
  return _this;
2200
2076
  }
2201
2077
 
2202
- _createClass(AddJob, [{
2203
- key: "UNSAFE_componentWillMount",
2204
- value: function UNSAFE_componentWillMount() {
2078
+ _createClass(Job, [{
2079
+ key: "UNSAFE_componentWillReceiveProps",
2080
+ value: function UNSAFE_componentWillReceiveProps(nextProps) {
2205
2081
  Session$1.checkLoggedIn(this, this.props.auth);
2206
2082
  }
2207
2083
  }, {
2208
- key: "componentDidMount",
2209
- value: function componentDidMount() {
2210
- this.getJobTypes();
2211
- if (this.state.jobId) this.getJob();
2212
- this.props.addRecentlyCreated('maintenance');
2084
+ key: "componentDidMount",
2085
+ value: function componentDidMount() {
2086
+ if (this.state.jobId) {
2087
+ this.getJob();
2088
+ this.getComments();
2089
+ }
2090
+ }
2091
+ }, {
2092
+ key: "renderStatusLabel",
2093
+ value: function renderStatusLabel() {
2094
+ if (!this.state.job.status) return null;
2095
+ var auth = this.props.auth;
2096
+
2097
+ if (Session$1.validateAccess(auth.site, 'maintenanceTracking', auth)) {
2098
+ return /*#__PURE__*/React.createElement("div", {
2099
+ className: "statusLabel pointer",
2100
+ onClick: this.onToggleStatusChanger,
2101
+ style: {
2102
+ backgroundColor: StatusTypes[this.state.job.status].color
2103
+ }
2104
+ }, /*#__PURE__*/React.createElement("span", {
2105
+ className: "statusLabel_text"
2106
+ }, StatusTypes[this.state.job.status].text), this.renderStatusChanger());
2107
+ }
2108
+
2109
+ return /*#__PURE__*/React.createElement("div", {
2110
+ className: "statusLabel",
2111
+ style: {
2112
+ backgroundColor: StatusTypes[this.state.job.status].color
2113
+ }
2114
+ }, /*#__PURE__*/React.createElement("span", {
2115
+ className: "statusLabel_text"
2116
+ }, StatusTypes[this.state.job.status].text));
2117
+ }
2118
+ }, {
2119
+ key: "renderNotesButton",
2120
+ value: function renderNotesButton() {
2121
+ var auth = this.props.auth;
2122
+ if (!Session$1.validateAccess(auth.site, 'maintenanceTracking', auth)) return null;
2123
+ return /*#__PURE__*/React.createElement("div", {
2124
+ className: "statusLabel pointer",
2125
+ onClick: this.onOpenAddNote,
2126
+ style: {
2127
+ backgroundColor: FeatureConfig.env.colourBrandingMain,
2128
+ marginLeft: 8
2129
+ }
2130
+ }, /*#__PURE__*/React.createElement("span", {
2131
+ className: "statusLabel_text"
2132
+ }, "Add Note"));
2213
2133
  }
2214
2134
  }, {
2215
- key: "renderTypeOptions",
2216
- value: function renderTypeOptions() {
2135
+ key: "renderStatusChanger",
2136
+ value: function renderStatusChanger() {
2217
2137
  var _this2 = this;
2218
2138
 
2219
- var source = this.state.types;
2220
- return source.map(function (ev) {
2221
- if (ev != null) {
2222
- return /*#__PURE__*/React.createElement(MenuItem, {
2223
- key: ev.typeName,
2224
- eventKey: ev.typeName,
2225
- active: _this2.state.type === ev.typeName
2226
- }, ev.typeName);
2227
- }
2139
+ if (!this.state.statusChangerOpen) return null;
2140
+ return /*#__PURE__*/React.createElement("div", {
2141
+ className: "statusChanger statusChanger-maintenance"
2142
+ }, Object.keys(StatusTypes).map(function (statusKey) {
2143
+ return /*#__PURE__*/React.createElement("div", {
2144
+ key: statusKey,
2145
+ className: "statusLabel",
2146
+ onClick: function onClick() {
2147
+ return _this2.onSelectStatus(statusKey);
2148
+ },
2149
+ style: {
2150
+ backgroundColor: StatusTypes[statusKey].color
2151
+ }
2152
+ }, /*#__PURE__*/React.createElement("span", {
2153
+ className: "statusLabel_text"
2154
+ }, StatusTypes[statusKey].text));
2155
+ }));
2156
+ }
2157
+ }, {
2158
+ key: "renderComment",
2159
+ value: function renderComment(c) {
2160
+ return /*#__PURE__*/React.createElement("div", {
2161
+ key: c.Id,
2162
+ className: "comment"
2163
+ }, /*#__PURE__*/React.createElement("p", {
2164
+ className: "comment_text"
2165
+ }, Helper$1.toParagraphed(c.Comment)), /*#__PURE__*/React.createElement("div", {
2166
+ className: "comment_bottom"
2167
+ }, /*#__PURE__*/React.createElement(Components$1.ProfilePic, {
2168
+ className: "comment_profilePic",
2169
+ size: 25,
2170
+ image: c.User.profilePic
2171
+ }), /*#__PURE__*/React.createElement("p", {
2172
+ className: "comment_name"
2173
+ }, c.User.displayName), /*#__PURE__*/React.createElement("p", {
2174
+ className: "comment_time"
2175
+ }, moment.utc(c.Timestamp).local().format('D MMM YYYY • h:mma'))));
2176
+ }
2177
+ }, {
2178
+ key: "renderCommentSection",
2179
+ value: function renderCommentSection() {
2180
+ var _this3 = this;
2228
2181
 
2229
- return null;
2230
- });
2182
+ if (this.state.loadingComments) return null;
2183
+ return /*#__PURE__*/React.createElement("div", {
2184
+ className: "padding-60 paddingLeft-20"
2185
+ }, /*#__PURE__*/React.createElement("div", {
2186
+ className: "newTopBar paddingLeft-40"
2187
+ }, /*#__PURE__*/React.createElement(Components$1.Text, {
2188
+ type: "formTitleSmall",
2189
+ className: "marginBottom-16"
2190
+ }, "Comments"), /*#__PURE__*/React.createElement("div", {
2191
+ className: "commentSection"
2192
+ }, this.state.comments.map(function (c) {
2193
+ return _this3.renderComment(c);
2194
+ })), /*#__PURE__*/React.createElement("div", {
2195
+ className: "commentReply"
2196
+ }, /*#__PURE__*/React.createElement("div", {
2197
+ className: "commentReply_button".concat(!_.isEmpty(this.state.commentInput) ? ' commentReply_button-active' : ''),
2198
+ onClick: this.onAddComment
2199
+ }, /*#__PURE__*/React.createElement(FontAwesome, {
2200
+ className: "commentReply_icon",
2201
+ name: "paper-plane-o"
2202
+ })), /*#__PURE__*/React.createElement(Textarea, {
2203
+ id: "commentInput",
2204
+ placeholder: "Reply here...",
2205
+ type: "text",
2206
+ className: "commentReply_input",
2207
+ value: this.state.commentInput,
2208
+ onChange: function onChange(e) {
2209
+ return _this3.onHandleChange(e);
2210
+ }
2211
+ }))));
2231
2212
  }
2232
2213
  }, {
2233
- key: "renderSuccess",
2234
- value: function renderSuccess() {
2235
- if (!this.state.success) return null;
2236
- return /*#__PURE__*/React.createElement(Components$1.SuccessPopup, {
2237
- text: "Maintenance request has been ".concat(this.state.id != null ? 'edited' : 'added'),
2238
- buttons: [{
2239
- type: 'outlined',
2240
- onClick: function onClick() {
2241
- window.history.back();
2242
- },
2243
- text: "Back to Maintenance"
2214
+ key: "renderInner",
2215
+ value: function renderInner() {
2216
+ if (this.state.job == null) return null;
2217
+ return /*#__PURE__*/React.createElement("div", {
2218
+ style: {
2219
+ paddingBottom: 40
2220
+ }
2221
+ }, /*#__PURE__*/React.createElement("div", {
2222
+ className: "padding-60 paddingVertical-40 bottomDivideBorder relative"
2223
+ }, /*#__PURE__*/React.createElement(Components$1.Text, {
2224
+ type: "formTitleLarge",
2225
+ className: "marginBottom-24"
2226
+ }, this.state.job.title || 'Request'), /*#__PURE__*/React.createElement("div", {
2227
+ className: "marginTop-16"
2228
+ }, /*#__PURE__*/React.createElement("div", {
2229
+ className: 'fieldLabel'
2230
+ }, "Request date"), /*#__PURE__*/React.createElement("div", {
2231
+ className: 'fontRegular fontSize-16 text-dark marginTop-5'
2232
+ }, moment.utc(this.state.job.createdTime).local().format('D MMM YY'))), /*#__PURE__*/React.createElement("div", {
2233
+ className: "marginTop-16"
2234
+ }, /*#__PURE__*/React.createElement("div", {
2235
+ className: 'fieldLabel'
2236
+ }, "Type"), /*#__PURE__*/React.createElement("div", {
2237
+ className: 'fontRegular fontSize-16 text-dark marginTop-5'
2238
+ }, this.state.job.type)), /*#__PURE__*/React.createElement("div", {
2239
+ className: "marginTop-16"
2240
+ }, /*#__PURE__*/React.createElement("div", {
2241
+ className: 'fieldLabel'
2242
+ }, "Location"), /*#__PURE__*/React.createElement("div", {
2243
+ className: 'fontRegular fontSize-16 text-dark marginTop-5'
2244
+ }, this.state.job.room)), /*#__PURE__*/React.createElement("div", {
2245
+ className: "marginTop-16"
2246
+ }, /*#__PURE__*/React.createElement("div", {
2247
+ className: 'fieldLabel'
2248
+ }, "Description ", this.state.job.image ? '- (image supplied)' : ''), /*#__PURE__*/React.createElement("div", {
2249
+ className: 'fontRegular fontSize-16 text-dark marginTop-5'
2250
+ }, this.state.job.description))), /*#__PURE__*/React.createElement("div", {
2251
+ className: "padding-60 paddingVertical-40 bottomDivideBorder"
2252
+ }, /*#__PURE__*/React.createElement(Components$1.Text, {
2253
+ type: "formTitleSmall",
2254
+ className: "marginBottom-16"
2255
+ }, "Contact Details"), /*#__PURE__*/React.createElement("div", {
2256
+ className: "marginTop-16"
2257
+ }, /*#__PURE__*/React.createElement("div", {
2258
+ className: 'fieldLabel'
2259
+ }, "Name"), /*#__PURE__*/React.createElement("div", {
2260
+ className: 'fontRegular fontSize-16 text-dark marginTop-5'
2261
+ }, this.state.job.userName)), /*#__PURE__*/React.createElement("div", {
2262
+ className: "marginTop-16"
2263
+ }, /*#__PURE__*/React.createElement("div", {
2264
+ className: 'fieldLabel'
2265
+ }, "Contact number"), /*#__PURE__*/React.createElement("div", {
2266
+ className: 'fontRegular fontSize-16 text-dark marginTop-5'
2267
+ }, _.isEmpty(this.state.job.phone) ? 'No phone provided' : this.state.job.phone)), /*#__PURE__*/React.createElement("div", {
2268
+ className: "marginTop-16"
2269
+ }, /*#__PURE__*/React.createElement("div", {
2270
+ className: 'fieldLabel'
2271
+ }, "Should person be home?"), /*#__PURE__*/React.createElement("div", {
2272
+ className: 'fontRegular fontSize-16 text-dark marginTop-5'
2273
+ }, this.state.job.isHome ? 'Yes' : 'No')), this.state.job.isHome && this.state.job.homeText && /*#__PURE__*/React.createElement("div", {
2274
+ className: "marginTop-16"
2275
+ }, /*#__PURE__*/React.createElement("div", {
2276
+ className: 'fieldLabel'
2277
+ }, "When"), /*#__PURE__*/React.createElement("div", {
2278
+ className: 'fontRegular fontSize-16 text-dark marginTop-5'
2279
+ }, this.state.job.homeText))), (this.state.job.image || this.state.job.images) && /*#__PURE__*/React.createElement("div", {
2280
+ className: "padding-60 paddingVertical-40 bottomDivideBorder"
2281
+ }, /*#__PURE__*/React.createElement(Components$1.Text, {
2282
+ type: "formTitleSmall",
2283
+ className: "marginBottom-16"
2284
+ }, "Image"), /*#__PURE__*/React.createElement("div", {
2285
+ style: {
2286
+ marginTop: 16,
2287
+ height: 180,
2288
+ width: 260,
2289
+ borderRadius: 4,
2290
+ border: '1px solid #aaa',
2291
+ backgroundColor: '#ddd',
2292
+ backgroundImage: "url(".concat(this.state.job.thumbnail, ")"),
2293
+ backgroundPosition: 'center'
2294
+ }
2295
+ })), this.renderCommentSection());
2296
+ }
2297
+ }, {
2298
+ key: "renderHistoryEntry",
2299
+ value: function renderHistoryEntry(e, i) {
2300
+ var job = this.state.job;
2301
+ var entryToUse = e || {
2302
+ timestamp: job.createdTime,
2303
+ status: 'Unassigned',
2304
+ user: {
2305
+ displayName: job.userName,
2306
+ id: job.userID,
2307
+ profilePic: job.userProfilePic
2308
+ }
2309
+ };
2310
+ return /*#__PURE__*/React.createElement("div", {
2311
+ className: "ticketHistoryEntry",
2312
+ key: i
2313
+ }, /*#__PURE__*/React.createElement("p", {
2314
+ className: "ticketHistoryEntry_timestamp"
2315
+ }, moment.utc(entryToUse.timestamp).local().format('D MMM YYYY h:mma')), /*#__PURE__*/React.createElement("div", {
2316
+ className: "statusLabel statusLabel-large statusLabel-full",
2317
+ style: {
2318
+ backgroundColor: StatusTypes[entryToUse.status].color
2319
+ }
2320
+ }, /*#__PURE__*/React.createElement("span", {
2321
+ className: "statusLabel_text"
2322
+ }, e ? "Marked as ".concat(StatusTypes[entryToUse.status].text) : 'Job opened')));
2323
+ }
2324
+ }, {
2325
+ key: "renderNote",
2326
+ value: function renderNote(note, index) {
2327
+ var _this4 = this;
2328
+
2329
+ return /*#__PURE__*/React.createElement("div", {
2330
+ className: "ticketHistoryEntry",
2331
+ key: index
2332
+ }, /*#__PURE__*/React.createElement("p", {
2333
+ className: "ticketHistoryEntry_timestamp"
2334
+ }, moment.utc(note.Timestamp).local().format('D MMM YYYY h:mma')), /*#__PURE__*/React.createElement("div", {
2335
+ className: "statusLabel statusLabel-large statusLabel-full",
2336
+ style: {
2337
+ backgroundColor: '#6e79c5'
2338
+ }
2339
+ }, /*#__PURE__*/React.createElement("span", {
2340
+ className: "statusLabel_text"
2341
+ }, "Staff Notes")), /*#__PURE__*/React.createElement("div", {
2342
+ className: "maintenanceNote"
2343
+ }, /*#__PURE__*/React.createElement("div", {
2344
+ className: "maintenanceNote_top"
2345
+ }, this.props.auth && this.props.auth.user && this.props.auth.user.Id === note.User.id && /*#__PURE__*/React.createElement(Components$1.SVGIcon, {
2346
+ colour: Colours.COLOUR_DUSK_LIGHT,
2347
+ icon: "more15",
2348
+ className: "maintenanceNote_moreIcon",
2349
+ onClick: function onClick() {
2350
+ return _this4.onOpenNoteMenu(index);
2351
+ }
2352
+ }), /*#__PURE__*/React.createElement("p", {
2353
+ className: "maintenanceNote_name"
2354
+ }, note.User.displayName), this.state.noteMenuOpen === index && /*#__PURE__*/React.createElement(Components$1.MoreMenu, {
2355
+ options: [{
2356
+ key: 'edit',
2357
+ text: 'Edit',
2358
+ onPress: function onPress() {
2359
+ return _this4.onOpenEditNote(note);
2360
+ }
2361
+ }, {
2362
+ key: 'delete',
2363
+ text: 'Delete',
2364
+ onPress: function onPress() {
2365
+ return _this4.onDeleteNote(note);
2366
+ }
2244
2367
  }]
2245
- });
2246
- }
2247
- }, {
2248
- key: "validateForm",
2249
- value: function validateForm() {
2250
- if (_.isEmpty(this.state.userName)) return false;
2251
- if (_.isEmpty(this.state.room)) return false;
2252
- if (_.isEmpty(this.state.title)) return false;
2253
- if (this.state.isHome && _.isEmpty(this.state.homeText)) return false;
2254
- return true;
2368
+ })), /*#__PURE__*/React.createElement("p", {
2369
+ className: "maintenanceNote_text"
2370
+ }, Helper$1.toParagraphed(note.Note)), note.Attachments.map(function (a, i) {
2371
+ return _this4.renderAttachment(a, i);
2372
+ })));
2255
2373
  }
2256
2374
  }, {
2257
- key: "renderSubmit",
2258
- value: function renderSubmit() {
2259
- var _this3 = this;
2375
+ key: "renderOverview",
2376
+ value: function renderOverview() {
2377
+ var _this5 = this;
2260
2378
 
2261
- if (this.state.updating) {
2262
- return /*#__PURE__*/React.createElement(Components$1.Button, {
2263
- buttonType: "secondary"
2264
- }, "Saving...");
2265
- }
2379
+ var job = this.state.job;
2380
+ if (!job || !job.history) return null;
2381
+
2382
+ var source = _.sortBy([].concat(_toConsumableArray(job.history.map(function (e) {
2383
+ return _objectSpread$3(_objectSpread$3({}, e), {}, {
2384
+ EntryType: 'status'
2385
+ });
2386
+ })), _toConsumableArray((job.Notes || []).map(function (e) {
2387
+ return _objectSpread$3(_objectSpread$3({}, e), {}, {
2388
+ timestamp: e.Timestamp,
2389
+ EntryType: 'note'
2390
+ });
2391
+ }))), 'timestamp');
2392
+
2393
+ return /*#__PURE__*/React.createElement("div", {
2394
+ className: "padding-32 paddingVertical-40 bottomDivideBorder relative"
2395
+ }, /*#__PURE__*/React.createElement("div", {
2396
+ className: "newTopBar clearfix flex flex-reverse"
2397
+ }, this.renderNotesButton(), this.renderStatusLabel(), /*#__PURE__*/React.createElement(Components$1.Text, {
2398
+ type: "formTitleSmall",
2399
+ className: "flex-1"
2400
+ }, "Status History")), this.renderHistoryEntry(null, -1), _.map(source, function (e, i) {
2401
+ switch (e.EntryType) {
2402
+ case 'status':
2403
+ return _this5.renderHistoryEntry(e, i);
2266
2404
 
2405
+ case 'note':
2406
+ return _this5.renderNote(e, i);
2407
+ }
2408
+ }));
2409
+ }
2410
+ }, {
2411
+ key: "renderButtons",
2412
+ value: function renderButtons() {
2267
2413
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Components$1.Button, {
2268
2414
  inline: true,
2269
2415
  buttonType: "tertiary",
2270
2416
  onClick: function onClick() {
2271
- return _this3.props.history.push('/requestsHub');
2417
+ window.history.back();
2272
2418
  },
2273
2419
  isActive: true,
2274
2420
  style: {
2275
2421
  marginRight: 16
2276
2422
  }
2277
- }, "Cancel"), /*#__PURE__*/React.createElement(Components$1.Button, {
2423
+ }, "Back"), Session$1.validateAccess(this.props.auth.site, 'maintenanceTracking', this.props.auth) && !_.isEmpty(this.state.job) && /*#__PURE__*/React.createElement(Link, {
2424
+ to: "/requestsHub/job/".concat(this.state.jobId)
2425
+ }, /*#__PURE__*/React.createElement(Components$1.Button, {
2278
2426
  inline: true,
2279
- buttonType: "primary",
2280
- onClick: this.onSave,
2281
- isActive: this.validateForm()
2282
- }, "Save"));
2427
+ style: {
2428
+ marginRight: 25
2429
+ },
2430
+ buttonType: "outlined",
2431
+ isActive: true,
2432
+ onClick: this.editJob
2433
+ }, "Edit Details")));
2283
2434
  }
2284
2435
  }, {
2285
- key: "renderMain",
2286
- value: function renderMain() {
2287
- var _this4 = this;
2436
+ key: "renderAttachment",
2437
+ value: function renderAttachment(attachment, index, onRemove) {
2438
+ if (!attachment) return null;
2439
+ return /*#__PURE__*/React.createElement(Components$1.Attachment, {
2440
+ key: index,
2441
+ uploading: attachment.Uploading,
2442
+ source: attachment.Source,
2443
+ title: attachment.Title,
2444
+ onRemove: onRemove ? function () {
2445
+ return onRemove(attachment);
2446
+ } : undefined
2447
+ });
2448
+ }
2449
+ }, {
2450
+ key: "renderAddNotePopup",
2451
+ value: function renderAddNotePopup() {
2452
+ var _this6 = this;
2288
2453
 
2289
- return /*#__PURE__*/React.createElement("div", {
2290
- style: {
2291
- marginBottom: 15
2292
- }
2293
- }, /*#__PURE__*/React.createElement("div", {
2294
- className: "padding-60 paddingVertical-40 bottomDivideBorder"
2295
- }, /*#__PURE__*/React.createElement(Components$1.Text, {
2296
- type: "formTitleLarge",
2297
- className: "marginBottom-24"
2298
- }, this.state.infoId == null ? 'New' : 'Edit', " Request"), /*#__PURE__*/React.createElement(Components$1.GenericInput, {
2299
- id: "userName",
2300
- type: "text",
2301
- label: "Name",
2302
- placeholder: "Insert name here",
2303
- value: this.state.userName,
2304
- onChange: function onChange(e) {
2305
- return _this4.onHandleChange(e);
2306
- },
2307
- isRequired: true,
2308
- alwaysShowLabel: true,
2309
- isValid: function isValid() {
2310
- return !_.isEmpty(_this4.state.userName);
2311
- },
2312
- showError: function showError() {
2313
- return _this4.state.showWarnings && _.isEmpty(_this4.state.userName);
2314
- }
2315
- }), /*#__PURE__*/React.createElement(Components$1.GenericInput, {
2316
- id: "room",
2317
- type: "text",
2318
- label: "Location",
2319
- placeholder: "Insert address here",
2320
- value: this.state.room,
2321
- onChange: function onChange(e) {
2322
- return _this4.onHandleChange(e);
2323
- },
2324
- isRequired: true,
2325
- alwaysShowLabel: true,
2326
- isValid: function isValid() {
2327
- return !_.isEmpty(_this4.state.room);
2328
- },
2329
- showError: function showError() {
2330
- return _this4.state.showWarnings && _.isEmpty(_this4.state.room);
2331
- }
2332
- }), /*#__PURE__*/React.createElement(Components$1.GenericInput, {
2333
- id: "phone",
2334
- type: "text",
2335
- label: "Contact number",
2336
- placeholder: "04XX XXX XXX",
2337
- value: this.state.phone // showError={this.state.showWarnings && !this.validateImage()}
2338
- ,
2339
- onChange: function onChange(e) {
2340
- return _this4.onHandleChange(e);
2341
- },
2342
- alwaysShowLabel: true
2343
- }), /*#__PURE__*/React.createElement("div", {
2344
- style: {
2345
- marginBottom: 15
2346
- }
2347
- }, /*#__PURE__*/React.createElement(Components$1.Text, {
2348
- type: "formLabel"
2349
- }, "Job Type"), /*#__PURE__*/React.createElement(DropdownButton, {
2350
- style: {
2351
- minWidth: 80
2352
- },
2353
- bsStyle: "default",
2354
- title: this.state.type,
2355
- id: "typeSelect",
2356
- onSelect: this.onSelectType
2357
- }, this.renderTypeOptions())), /*#__PURE__*/React.createElement(Components$1.GenericInput, {
2358
- id: "title",
2359
- label: "Title for the work required",
2360
- type: "textarea",
2361
- placeholder: "Title for the work required",
2362
- value: this.state.title,
2363
- onChange: function onChange(e) {
2364
- return _this4.onHandleChange(e);
2365
- },
2366
- inputStyle: {
2367
- height: 80
2368
- },
2369
- isRequired: true,
2370
- isValid: function isValid() {
2371
- return !_.isEmpty(_this4.state.title);
2372
- },
2373
- showError: function showError() {
2374
- return _this4.state.showWarnings && _.isEmpty(_this4.state.title);
2375
- },
2376
- alwaysShowLabel: true
2377
- }), /*#__PURE__*/React.createElement(Components$1.GenericInput, {
2378
- id: "description",
2379
- label: "Description of work required",
2380
- type: "textarea",
2381
- placeholder: "Description of work required",
2382
- value: this.state.description,
2383
- onChange: function onChange(e) {
2384
- return _this4.onHandleChange(e);
2385
- },
2386
- inputStyle: {
2387
- height: 80
2388
- },
2389
- alwaysShowLabel: true
2390
- }), /*#__PURE__*/React.createElement(Components$1.RadioButton, {
2391
- label: "Person must be home during work?",
2392
- isActive: this.state.isHome,
2393
- options: [{
2394
- Label: 'No',
2395
- Value: false,
2396
- onChange: function onChange() {
2397
- return _this4.setState({
2398
- isHome: false
2399
- });
2400
- }
2454
+ if (!this.state.addNoteOpen) return null;
2455
+
2456
+ if (this.state.submittingNote) {
2457
+ return /*#__PURE__*/React.createElement(Components$1.Popup, {
2458
+ title: "Saving Note",
2459
+ maxWidth: 600,
2460
+ hasPadding: true
2461
+ }, /*#__PURE__*/React.createElement("div", {
2462
+ className: "flex flex-center-row"
2463
+ }, /*#__PURE__*/React.createElement(FontAwesome, {
2464
+ className: "spinner",
2465
+ name: "spinner fa-pulse fa-fw"
2466
+ })));
2467
+ }
2468
+
2469
+ return /*#__PURE__*/React.createElement(Components$1.Popup, {
2470
+ title: "".concat(this.state.editingNote ? 'Edit' : 'Add', " Note"),
2471
+ onClose: this.onCloseAddNote,
2472
+ maxWidth: 600,
2473
+ hasPadding: true,
2474
+ buttons: [{
2475
+ type: 'primary',
2476
+ onClick: this.onConfirmAddNote,
2477
+ isActive: this.isReadyToSaveNote(),
2478
+ text: 'Save'
2401
2479
  }, {
2402
- Label: 'Yes',
2403
- Value: true,
2404
- onChange: function onChange() {
2405
- return _this4.setState({
2406
- isHome: true
2407
- });
2408
- }
2480
+ type: 'tertiary',
2481
+ onClick: this.onCloseAddNote,
2482
+ isActive: true,
2483
+ text: 'Cancel'
2409
2484
  }]
2410
- }), this.state.isHome && /*#__PURE__*/React.createElement(Components$1.GenericInput, {
2411
- style: {
2412
- marginTop: 16
2413
- },
2414
- label: "Description of person's available times",
2415
- id: "homeText",
2485
+ }, /*#__PURE__*/React.createElement(Components$1.GenericInput, {
2486
+ id: "noteInput",
2416
2487
  type: "textarea",
2417
- placeholder: "Description of person's available times",
2418
- value: this.state.homeText,
2488
+ componentClass: "textarea",
2489
+ value: this.state.noteInput,
2490
+ placeholder: "Enter note",
2419
2491
  onChange: function onChange(e) {
2420
- return _this4.onHandleChange(e);
2421
- },
2422
- inputStyle: {
2423
- height: 80
2492
+ return _this6.onHandleChange(e);
2424
2493
  },
2425
- isRequired: true,
2426
- isValid: function isValid() {
2427
- return !_.isEmpty(_this4.state.homeText);
2494
+ inputStyle: {
2495
+ width: 400
2496
+ }
2497
+ }), /*#__PURE__*/React.createElement(Components$1.Text, {
2498
+ type: "h5"
2499
+ }, "Attachments"), this.state.noteAttachments.map(function (a, i) {
2500
+ return _this6.renderAttachment(a, i, _this6.onRemoveAttachment);
2501
+ }), /*#__PURE__*/React.createElement("input", {
2502
+ ref: function ref(input) {
2503
+ return _this6.attachmentInput = input;
2428
2504
  },
2429
- showError: function showError() {
2430
- return _this4.state.showWarnings && _.isEmpty(_this4.state.homeText);
2505
+ id: "attachmentInput",
2506
+ type: "file",
2507
+ className: "fileInput",
2508
+ onChange: function onChange(e) {
2509
+ return _this6.onHandlePDFFileChange(e);
2431
2510
  },
2432
- alwaysShowLabel: true
2433
- })));
2511
+ accept: "application/pdf"
2512
+ }), /*#__PURE__*/React.createElement("div", {
2513
+ className: "iconTextButton",
2514
+ onClick: function onClick() {
2515
+ _this6.attachmentInput.click();
2516
+ }
2517
+ }, /*#__PURE__*/React.createElement(FontAwesome, {
2518
+ className: "iconTextButton_icon",
2519
+ name: "paperclip"
2520
+ }), /*#__PURE__*/React.createElement("p", {
2521
+ className: "iconTextButton_text"
2522
+ }, "Add Attachment")));
2434
2523
  }
2435
2524
  }, {
2436
2525
  key: "render",
2437
2526
  value: function render() {
2438
- var success = this.state.success;
2439
- return /*#__PURE__*/React.createElement(Components$1.OverlayPage, null, /*#__PURE__*/React.createElement(Components$1.OverlayPageContents, {
2440
- noBottomButtons: success
2441
- }, /*#__PURE__*/React.createElement(Components$1.OverlayPageSection, {
2527
+ return /*#__PURE__*/React.createElement(Components$1.OverlayPage, null, this.renderAddNotePopup(), /*#__PURE__*/React.createElement(Components$1.OverlayPageContents, null, /*#__PURE__*/React.createElement(Components$1.OverlayPageSection, {
2442
2528
  className: "pageSectionWrapper--newPopup"
2443
- }, /*#__PURE__*/React.createElement("div", null, this.renderSuccess(), !success && this.renderMain()))), /*#__PURE__*/React.createElement(Components$1.OverlayPageBottomButtons, null, this.renderSubmit()));
2529
+ }, this.renderInner()), /*#__PURE__*/React.createElement(Components$1.OverlayPageSection, {
2530
+ className: "pageSectionWrapper--newPopupSide pageSectionWrapper--newPopupSide-fixedWidth"
2531
+ }, this.renderOverview())), /*#__PURE__*/React.createElement(Components$1.OverlayPageBottomButtons, null, this.renderButtons()));
2444
2532
  }
2445
2533
  }]);
2446
2534
 
2447
- return AddJob;
2535
+ return Job;
2448
2536
  }(Component);
2449
2537
 
2450
2538
  var mapStateToProps$1 = function mapStateToProps(state) {
@@ -2454,32 +2542,31 @@ var mapStateToProps$1 = function mapStateToProps(state) {
2454
2542
  };
2455
2543
  };
2456
2544
 
2457
- var AddJob$1 = connect(mapStateToProps$1, {
2458
- jobsUpdate: jobsUpdate,
2459
- jobsLoaded: jobsLoaded,
2460
- addRecentlyCreated: Actions.addRecentlyCreated
2461
- })(withRouter(AddJob));
2545
+ var Job$1 = connect(mapStateToProps$1, {
2546
+ jobsLoaded: jobsLoaded
2547
+ })(withRouter(Job));
2462
2548
 
2463
2549
  function _createSuper$6(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$6(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
2464
2550
 
2465
2551
  function _isNativeReflectConstruct$6() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2466
- var Session = PlussCore.Session,
2552
+ var Actions = PlussCore.Actions,
2467
2553
  Components = PlussCore.Components,
2468
- Helper = PlussCore.Helper;
2554
+ Helper = PlussCore.Helper,
2555
+ Session = PlussCore.Session;
2469
2556
 
2470
- var JobTypes = /*#__PURE__*/function (_Component) {
2471
- _inherits(JobTypes, _Component);
2557
+ var AddJob = /*#__PURE__*/function (_Component) {
2558
+ _inherits(AddJob, _Component);
2472
2559
 
2473
- var _super = _createSuper$6(JobTypes);
2560
+ var _super = _createSuper$6(AddJob);
2474
2561
 
2475
- function JobTypes(props) {
2562
+ function AddJob(props) {
2476
2563
  var _this;
2477
2564
 
2478
- _classCallCheck(this, JobTypes);
2565
+ _classCallCheck(this, AddJob);
2479
2566
 
2480
2567
  _this = _super.call(this, props);
2481
2568
 
2482
- _defineProperty(_assertThisInitialized(_this), "getJobTypes", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
2569
+ _defineProperty(_assertThisInitialized(_this), "getJob", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
2483
2570
  var res;
2484
2571
  return _regeneratorRuntime.wrap(function _callee$(_context) {
2485
2572
  while (1) {
@@ -2487,141 +2574,76 @@ var JobTypes = /*#__PURE__*/function (_Component) {
2487
2574
  case 0:
2488
2575
  _context.prev = 0;
2489
2576
  _context.next = 3;
2490
- return maintenanceActions.getJobTypes(_this.props.auth.site);
2577
+ return maintenanceActions.getJob(_this.props.auth.site, _this.state.jobId);
2491
2578
 
2492
2579
  case 3:
2493
2580
  res = _context.sent;
2494
- if (res.data != null) _this.props.jobTypesLoaded(res.data);
2495
- _context.next = 10;
2496
- break;
2497
-
2498
- case 7:
2499
- _context.prev = 7;
2500
- _context.t0 = _context["catch"](0);
2501
- console.error('getJobTypes', _context.t0);
2581
+ res.data.location = res.data.site;
2502
2582
 
2503
- case 10:
2504
- _context.prev = 10;
2583
+ _this.setState(res.data);
2505
2584
 
2506
- _this.setState({
2507
- loading: false
2508
- });
2585
+ _context.next = 11;
2586
+ break;
2509
2587
 
2510
- return _context.finish(10);
2588
+ case 8:
2589
+ _context.prev = 8;
2590
+ _context.t0 = _context["catch"](0);
2591
+ console.error('getJob', _context.t0);
2511
2592
 
2512
- case 13:
2593
+ case 11:
2513
2594
  case "end":
2514
2595
  return _context.stop();
2515
2596
  }
2516
2597
  }
2517
- }, _callee, null, [[0, 7, 10, 13]]);
2598
+ }, _callee, null, [[0, 8]]);
2518
2599
  })));
2519
2600
 
2520
- _defineProperty(_assertThisInitialized(_this), "sortByCol", function (col) {
2521
- if (_this.state.sortColumn === col) {
2522
- _this.setState({
2523
- sortDesc: !_this.state.sortDesc
2524
- });
2525
- } else {
2526
- _this.setState({
2527
- sortColumn: col,
2528
- sortDesc: false
2529
- });
2530
- }
2531
- });
2532
-
2533
- _defineProperty(_assertThisInitialized(_this), "validateEmail", function () {
2534
- var jobTypeEmail = _this.state.jobTypeEmail;
2535
- return !_.isEmpty(jobTypeEmail) && Helper.isEmail(jobTypeEmail);
2536
- });
2537
-
2538
- _defineProperty(_assertThisInitialized(_this), "isJobTypeValid", function () {
2539
- var _this$state = _this.state,
2540
- jobTypeName = _this$state.jobTypeName,
2541
- jobTypeDescription = _this$state.jobTypeDescription;
2542
- if (_.isEmpty(jobTypeName)) return false;
2543
- if (!_this.validateEmail()) return false;
2544
- if (_.isEmpty(jobTypeDescription)) return false;
2545
- return true;
2546
- });
2547
-
2548
- _defineProperty(_assertThisInitialized(_this), "onRemoveJobType", /*#__PURE__*/function () {
2549
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(ev) {
2550
- var index, newJobTypes;
2551
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
2552
- while (1) {
2553
- switch (_context2.prev = _context2.next) {
2554
- case 0:
2555
- if (window.confirm("Are you sure you want to delete ".concat(ev.typeName, "?"))) {
2556
- _context2.next = 2;
2557
- break;
2558
- }
2559
-
2560
- return _context2.abrupt("return");
2561
-
2562
- case 2:
2563
- _context2.prev = 2;
2564
- _context2.next = 5;
2565
- return maintenanceActions.deleteJobType(_this.props.auth.site, ev.id);
2601
+ _defineProperty(_assertThisInitialized(_this), "getJobTypes", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
2602
+ var res;
2603
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
2604
+ while (1) {
2605
+ switch (_context2.prev = _context2.next) {
2606
+ case 0:
2607
+ _context2.prev = 0;
2608
+ _context2.next = 3;
2609
+ return maintenanceActions.getJobTypes(_this.props.auth.site);
2566
2610
 
2567
- case 5:
2568
- index = _.findIndex(_this.state.jobList, function (job) {
2569
- return job != null && job.id === ev.id;
2570
- });
2611
+ case 3:
2612
+ res = _context2.sent;
2571
2613
 
2572
- if (index > -1) {
2573
- newJobTypes = _toConsumableArray(_this.state.jobList);
2574
- newJobTypes[index].Deleted = true;
2614
+ _this.setState({
2615
+ types: res.data
2616
+ });
2575
2617
 
2576
- _this.props.jobTypesLoaded(newJobTypes);
2577
- }
2618
+ _this.getDefaultJob();
2578
2619
 
2579
- _context2.next = 13;
2580
- break;
2620
+ _context2.next = 11;
2621
+ break;
2581
2622
 
2582
- case 9:
2583
- _context2.prev = 9;
2584
- _context2.t0 = _context2["catch"](2);
2585
- console.error('onRemoveJobType', _context2.t0);
2586
- alert('Something went wrong with the request. Please try again.');
2623
+ case 8:
2624
+ _context2.prev = 8;
2625
+ _context2.t0 = _context2["catch"](0);
2626
+ console.error('getJobTypes', _context2.t0);
2587
2627
 
2588
- case 13:
2589
- case "end":
2590
- return _context2.stop();
2591
- }
2628
+ case 11:
2629
+ case "end":
2630
+ return _context2.stop();
2592
2631
  }
2593
- }, _callee2, null, [[2, 9]]);
2594
- }));
2595
-
2596
- return function (_x) {
2597
- return _ref2.apply(this, arguments);
2598
- };
2599
- }());
2600
-
2601
- _defineProperty(_assertThisInitialized(_this), "onShowJobType", function () {
2602
- var job = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
2632
+ }
2633
+ }, _callee2, null, [[0, 8]]);
2634
+ })));
2603
2635
 
2604
- _this.setState({
2605
- showJobType: true,
2606
- jobTypeId: job ? job.id : null,
2607
- jobTypeName: job ? job.typeName : '',
2608
- jobTypeEmail: job ? job.email : '',
2609
- jobTypeDescription: job ? job.description : '',
2610
- jobTypeLevel: job ? job.level : 1
2611
- });
2636
+ _defineProperty(_assertThisInitialized(_this), "getDefaultJob", function () {
2637
+ if (_this.state.types.length !== 0 && _this.state.jobId == null) {
2638
+ _this.setState({
2639
+ type: _this.state.types[0].typeName
2640
+ });
2641
+ }
2612
2642
  });
2613
2643
 
2614
- _defineProperty(_assertThisInitialized(_this), "onHideJobType", function () {
2615
- if (_this.state.submitting) return;
2616
-
2644
+ _defineProperty(_assertThisInitialized(_this), "onSelectType", function (key, e) {
2617
2645
  _this.setState({
2618
- showWarnings: false,
2619
- showJobType: false,
2620
- jobTypeId: null,
2621
- jobTypeName: '',
2622
- jobTypeEmail: '',
2623
- jobTypeDescription: '',
2624
- jobTypeLevel: 1
2646
+ type: key
2625
2647
  });
2626
2648
  });
2627
2649
 
@@ -2633,17 +2655,11 @@ var JobTypes = /*#__PURE__*/function (_Component) {
2633
2655
  });
2634
2656
 
2635
2657
  _defineProperty(_assertThisInitialized(_this), "onSave", function () {
2636
- var site = _this.props.auth.site;
2637
- var _this$state2 = _this.state,
2638
- submitting = _this$state2.submitting,
2639
- jobTypeId = _this$state2.jobTypeId,
2640
- jobTypeName = _this$state2.jobTypeName,
2641
- jobTypeEmail = _this$state2.jobTypeEmail,
2642
- jobTypeDescription = _this$state2.jobTypeDescription,
2643
- jobTypeLevel = _this$state2.jobTypeLevel;
2644
- if (submitting) return;
2658
+ _this.setState({
2659
+ showWarnings: false
2660
+ });
2645
2661
 
2646
- if (!_this.isJobTypeValid()) {
2662
+ if (!_this.validateForm()) {
2647
2663
  _this.setState({
2648
2664
  showWarnings: true
2649
2665
  });
@@ -2651,393 +2667,349 @@ var JobTypes = /*#__PURE__*/function (_Component) {
2651
2667
  return;
2652
2668
  }
2653
2669
 
2654
- _this.setState({
2655
- submitting: true
2656
- }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
2657
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
2658
- while (1) {
2659
- switch (_context3.prev = _context3.next) {
2660
- case 0:
2661
- _context3.prev = 0;
2662
-
2663
- if (!jobTypeId) {
2664
- _context3.next = 6;
2665
- break;
2666
- }
2667
-
2668
- _context3.next = 4;
2669
- return maintenanceActions.editJobType(site, jobTypeId, jobTypeName, jobTypeEmail, jobTypeDescription, jobTypeLevel);
2670
-
2671
- case 4:
2672
- _context3.next = 8;
2673
- break;
2674
-
2675
- case 6:
2676
- _context3.next = 8;
2677
- return maintenanceActions.addJobType(site, jobTypeName, jobTypeEmail, jobTypeDescription, jobTypeLevel);
2670
+ if (_this.state.updating) return;
2678
2671
 
2679
- case 8:
2680
- _this.props.jobTypesUpdate(site);
2672
+ _this.setState({
2673
+ updating: true
2674
+ });
2681
2675
 
2682
- _this.setState({
2683
- submitting: false
2684
- }, _this.onHideJobType);
2676
+ var job = {
2677
+ id: _this.state.id,
2678
+ userID: _this.state.userID,
2679
+ userName: _this.state.userName,
2680
+ room: _this.state.room,
2681
+ phone: _this.state.phone,
2682
+ location: _this.state.location,
2683
+ title: _this.state.title,
2684
+ description: _this.state.description,
2685
+ isHome: _this.state.isHome,
2686
+ homeText: _this.state.homeText,
2687
+ type: _this.state.type,
2688
+ date: null,
2689
+ image: _this.state.image
2690
+ };
2685
2691
 
2686
- _context3.next = 17;
2687
- break;
2692
+ if (_this.state.id != null) {
2693
+ maintenanceActions.editJob(job, _this.props.auth.site).then(function (res) {
2694
+ _this.setState({
2695
+ success: true,
2696
+ updating: false
2697
+ });
2688
2698
 
2689
- case 12:
2690
- _context3.prev = 12;
2691
- _context3.t0 = _context3["catch"](0);
2692
- console.error('onSave', _context3.t0);
2699
+ _this.props.jobsLoaded([job]);
2700
+ }).catch(function (res) {
2701
+ _this.setState({
2702
+ updating: false
2703
+ });
2693
2704
 
2694
- _this.setState({
2695
- submitting: false
2696
- });
2705
+ alert('Something went wrong with the request. Please try again.');
2706
+ });
2707
+ } else {
2708
+ // Create New Job
2709
+ job.userID = 'undefined';
2710
+ maintenanceActions.createJob(job).then(function (res) {
2711
+ _this.setState({
2712
+ success: true,
2713
+ updating: false
2714
+ });
2697
2715
 
2698
- alert('Something went wrong with the request. Please try again.');
2716
+ _this.props.jobsUpdate(_this.props.auth.site);
2717
+ }).catch(function (res) {
2718
+ _this.setState({
2719
+ updating: false
2720
+ });
2699
2721
 
2700
- case 17:
2701
- case "end":
2702
- return _context3.stop();
2703
- }
2704
- }
2705
- }, _callee3, null, [[0, 12]]);
2706
- })));
2722
+ alert('Something went wrong with the request. Please try again.');
2723
+ });
2724
+ }
2707
2725
  });
2708
2726
 
2709
2727
  _this.state = {
2710
- jobList: [],
2711
- showCompleted: false,
2712
- sortColumn: 'name',
2713
- sortDesc: false,
2714
- loading: true,
2715
- showJobType: false,
2716
- jobTypeId: null,
2717
- jobTypeName: '',
2718
- jobTypeEmail: '',
2719
- jobTypeDescription: '',
2720
- jobTypeLevel: 1,
2728
+ jobId: Helper.safeReadParams(_this.props, 'jobId') ? _this.props.match.params.jobId : null,
2729
+ job: null,
2730
+ showingSelector: false,
2731
+ updating: false,
2732
+ connected: false,
2733
+ types: [],
2734
+ id: null,
2735
+ userID: '',
2736
+ userName: '',
2737
+ room: '',
2738
+ phone: '',
2739
+ location: _this.props.auth.site,
2740
+ title: '',
2741
+ description: '',
2742
+ isHome: false,
2743
+ homeText: '',
2744
+ type: 'General',
2745
+ image: null,
2746
+ thumbnail: null,
2721
2747
  showWarnings: false,
2722
- submitting: false
2748
+ success: false
2723
2749
  };
2724
2750
  return _this;
2725
2751
  }
2726
2752
 
2727
- _createClass(JobTypes, [{
2728
- key: "componentWillMount",
2729
- value: function componentWillMount() {
2730
- this.updateProps(this.props);
2753
+ _createClass(AddJob, [{
2754
+ key: "UNSAFE_componentWillMount",
2755
+ value: function UNSAFE_componentWillMount() {
2731
2756
  Session.checkLoggedIn(this, this.props.auth);
2732
2757
  }
2733
2758
  }, {
2734
2759
  key: "componentDidMount",
2735
2760
  value: function componentDidMount() {
2736
2761
  this.getJobTypes();
2762
+ if (this.state.jobId) this.getJob();
2763
+ this.props.addRecentlyCreated('maintenance');
2737
2764
  }
2738
2765
  }, {
2739
- key: "componentWillReceiveProps",
2740
- value: function componentWillReceiveProps(nextProps) {
2741
- this.updateProps(nextProps);
2742
- }
2743
- }, {
2744
- key: "updateProps",
2745
- value: function updateProps(props) {
2746
- this.setState({
2747
- jobList: props.jobtypes
2748
- });
2749
- }
2750
- }, {
2751
- key: "renderList",
2752
- value: function renderList() {
2766
+ key: "renderTypeOptions",
2767
+ value: function renderTypeOptions() {
2753
2768
  var _this2 = this;
2754
2769
 
2755
- var source = _.sortBy(this.state.jobList, this.state.sortColumn);
2756
-
2757
- if (this.state.sortDesc) source.reverse();
2758
- source = _.filter(source, function (ev) {
2759
- if (!ev) return false;
2760
- if (ev.Deleted) return false;
2761
- return true;
2762
- });
2763
- return source.map(function (ev, index) {
2770
+ var source = this.state.types;
2771
+ return source.map(function (ev) {
2764
2772
  if (ev != null) {
2765
- return /*#__PURE__*/React.createElement("tr", {
2766
- key: index
2767
- }, /*#__PURE__*/React.createElement("td", {
2768
- className: "table-TitleColumn"
2769
- }, /*#__PURE__*/React.createElement("a", {
2770
- onClick: function onClick() {
2771
- return _this2.onShowJobType(ev);
2772
- }
2773
- }, ev.typeName)), /*#__PURE__*/React.createElement("td", null, ev.description), /*#__PURE__*/React.createElement("td", null, ev.email), /*#__PURE__*/React.createElement("td", {
2774
- className: "table-options"
2775
- }, /*#__PURE__*/React.createElement("div", {
2776
- style: {
2777
- display: 'flex',
2778
- alignItems: 'center'
2779
- }
2780
- }, Session.validateAccess(_this2.props.auth.site, 'maintenanceTypes', _this2.props.auth) && /*#__PURE__*/React.createElement("a", {
2781
- onClick: function onClick() {
2782
- return _this2.onShowJobType(ev);
2783
- }
2784
- }, /*#__PURE__*/React.createElement(FontAwesome, {
2785
- style: {
2786
- fontSize: 20,
2787
- padding: 5,
2788
- marginLeft: 12,
2789
- cursor: 'pointer'
2790
- },
2791
- name: "pencil"
2792
- })), Session.validateAccess(_this2.props.auth.site, 'maintenanceTypes', _this2.props.auth) && /*#__PURE__*/React.createElement("a", {
2793
- onClick: function onClick() {
2794
- return _this2.onRemoveJobType(ev);
2795
- }
2796
- }, /*#__PURE__*/React.createElement(FontAwesome, {
2797
- style: {
2798
- fontSize: 20,
2799
- padding: 5,
2800
- marginLeft: 8,
2801
- cursor: 'pointer'
2802
- },
2803
- name: "minus-circle"
2804
- })))));
2773
+ return /*#__PURE__*/React.createElement(MenuItem, {
2774
+ key: ev.typeName,
2775
+ eventKey: ev.typeName,
2776
+ active: _this2.state.type === ev.typeName
2777
+ }, ev.typeName);
2805
2778
  }
2806
2779
 
2807
2780
  return null;
2808
2781
  });
2809
2782
  }
2810
2783
  }, {
2811
- key: "renderView",
2812
- value: function renderView() {
2813
- var _this3 = this;
2814
-
2815
- return /*#__PURE__*/React.createElement(Table, {
2816
- className: "plussTable",
2817
- striped: true,
2818
- bordered: true,
2819
- condensed: true,
2820
- hover: true,
2821
- style: {
2822
- minWidth: '100%'
2823
- }
2824
- }, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", {
2825
- style: {
2826
- cursor: 'pointer'
2827
- },
2828
- onClick: function onClick() {
2829
- return _this3.sortByCol('name');
2830
- }
2831
- }, "Request type"), /*#__PURE__*/React.createElement("th", {
2832
- style: {
2833
- cursor: 'pointer'
2834
- },
2835
- onClick: function onClick() {
2836
- return _this3.sortByCol('name');
2837
- }
2838
- }, "Type Description"), /*#__PURE__*/React.createElement("th", {
2839
- style: {
2840
- cursor: 'pointer'
2841
- },
2842
- onClick: function onClick() {
2843
- return _this3.sortByCol('email');
2844
- }
2845
- }, "Email"), /*#__PURE__*/React.createElement("th", {
2846
- style: {
2847
- width: 70
2848
- }
2849
- }))), /*#__PURE__*/React.createElement("tbody", null, this.renderList()));
2850
- }
2851
- }, {
2852
- key: "renderEmpty",
2853
- value: function renderEmpty() {
2854
- return /*#__PURE__*/React.createElement("div", {
2855
- style: {
2856
- display: 'flex',
2857
- flexDirection: 'column',
2858
- flex: 1,
2859
- justifyContent: 'center',
2860
- alignItems: 'center',
2861
- marginTop: 32
2862
- }
2863
- }, /*#__PURE__*/React.createElement("div", {
2864
- className: "emptyState"
2865
- }), /*#__PURE__*/React.createElement("div", {
2866
- className: "marginTop-32",
2867
- style: {
2868
- maxWidth: 500,
2869
- textAlign: 'center'
2870
- }
2871
- }, /*#__PURE__*/React.createElement("span", {
2872
- className: "fontRegular fontSize-13"
2873
- }, "Please add the many categories of request types that exist in your village which work alongside the Maintenance area.")), /*#__PURE__*/React.createElement("div", {
2874
- className: "marginTop-8 fontRegular fontSize-13",
2875
- style: {
2876
- maxWidth: 500,
2877
- textAlign: 'center'
2878
- }
2879
- }, "Examples might be; OH&S, Electrical, General. Remember to add a description too."));
2784
+ key: "renderSuccess",
2785
+ value: function renderSuccess() {
2786
+ if (!this.state.success) return null;
2787
+ return /*#__PURE__*/React.createElement(Components.SuccessPopup, {
2788
+ text: "Maintenance request has been ".concat(this.state.id != null ? 'edited' : 'added'),
2789
+ buttons: [{
2790
+ type: 'outlined',
2791
+ onClick: function onClick() {
2792
+ window.history.back();
2793
+ },
2794
+ text: "Back to Maintenance"
2795
+ }]
2796
+ });
2880
2797
  }
2881
2798
  }, {
2882
- key: "renderContent",
2883
- value: function renderContent() {
2884
- if (_.isEmpty(this.state.jobList)) return this.renderEmpty();
2885
- return this.renderView();
2799
+ key: "validateForm",
2800
+ value: function validateForm() {
2801
+ if (_.isEmpty(this.state.userName)) return false;
2802
+ if (_.isEmpty(this.state.room)) return false;
2803
+ if (_.isEmpty(this.state.title)) return false;
2804
+ if (this.state.isHome && _.isEmpty(this.state.homeText)) return false;
2805
+ return true;
2886
2806
  }
2887
2807
  }, {
2888
- key: "renderJobTypes",
2889
- value: function renderJobTypes() {
2890
- var _this4 = this;
2891
-
2892
- var _this$state3 = this.state,
2893
- jobList = _this$state3.jobList,
2894
- loading = _this$state3.loading;
2808
+ key: "renderSubmit",
2809
+ value: function renderSubmit() {
2810
+ var _this3 = this;
2895
2811
 
2896
- if (jobList.length === 0 && loading) {
2897
- return /*#__PURE__*/React.createElement("div", {
2898
- style: {
2899
- minWidth: '100%'
2900
- }
2901
- }, /*#__PURE__*/React.createElement("div", {
2902
- className: "padding-60 paddingVertical-40",
2903
- style: {
2904
- textAlign: 'center'
2905
- }
2906
- }, /*#__PURE__*/React.createElement(FontAwesome, {
2907
- style: {
2908
- fontSize: 30,
2909
- color: FeatureConfig.env.colourBrandingOff
2910
- },
2911
- name: "spinner fa-pulse fa-fw"
2912
- })));
2812
+ if (this.state.updating) {
2813
+ return /*#__PURE__*/React.createElement(Components.Button, {
2814
+ buttonType: "secondary"
2815
+ }, "Saving...");
2913
2816
  }
2914
2817
 
2915
- return /*#__PURE__*/React.createElement("div", {
2916
- style: {
2917
- minWidth: '100%'
2918
- }
2919
- }, /*#__PURE__*/React.createElement("div", {
2920
- className: "flex flex-row flex-center flex-between marginBottom-32"
2921
- }, /*#__PURE__*/React.createElement(Components.PageTitle, null, "Request Types"), /*#__PURE__*/React.createElement(Components.AddButton, {
2818
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Components.Button, {
2819
+ inline: true,
2820
+ buttonType: "tertiary",
2922
2821
  onClick: function onClick() {
2923
- return _this4.onShowJobType();
2822
+ return _this3.props.history.push('/requestsHub');
2924
2823
  },
2925
- text: "NEW REQUEST TYPE"
2926
- })), this.renderContent());
2824
+ isActive: true,
2825
+ style: {
2826
+ marginRight: 16
2827
+ }
2828
+ }, "Cancel"), /*#__PURE__*/React.createElement(Components.Button, {
2829
+ inline: true,
2830
+ buttonType: "primary",
2831
+ onClick: this.onSave,
2832
+ isActive: this.validateForm()
2833
+ }, "Save"));
2927
2834
  }
2928
2835
  }, {
2929
- key: "renderNewUserTypePopup",
2930
- value: function renderNewUserTypePopup() {
2931
- var _this5 = this;
2836
+ key: "renderMain",
2837
+ value: function renderMain() {
2838
+ var _this4 = this;
2932
2839
 
2933
- var _this$state4 = this.state,
2934
- submitting = _this$state4.submitting,
2935
- showJobType = _this$state4.showJobType,
2936
- jobTypeId = _this$state4.jobTypeId,
2937
- showWarnings = _this$state4.showWarnings,
2938
- jobTypeName = _this$state4.jobTypeName,
2939
- jobTypeEmail = _this$state4.jobTypeEmail,
2940
- jobTypeDescription = _this$state4.jobTypeDescription;
2941
- if (!showJobType) return null;
2942
- return /*#__PURE__*/React.createElement(Components.Popup, {
2943
- maxWidth: 800,
2944
- hasPadding: true,
2945
- buttons: [{
2946
- type: 'primaryAction',
2947
- onClick: this.onSave,
2948
- isActive: !submitting && this.isJobTypeValid(),
2949
- text: submitting ? 'Saving...' : 'Save',
2950
- className: 'popupButton'
2951
- }, {
2952
- type: 'outlinedAction',
2953
- onClick: this.onHideJobType,
2954
- isActive: !submitting,
2955
- text: 'Cancel',
2956
- className: 'popupButton'
2957
- }],
2958
- onClose: this.onHideJobType,
2959
- title: jobTypeId ? 'Edit Request Type' : 'Create New Request Type'
2960
- }, /*#__PURE__*/React.createElement(Components.GenericInput, {
2961
- id: "jobTypeName",
2840
+ return /*#__PURE__*/React.createElement("div", {
2841
+ style: {
2842
+ marginBottom: 15
2843
+ }
2844
+ }, /*#__PURE__*/React.createElement("div", {
2845
+ className: "padding-60 paddingVertical-40 bottomDivideBorder"
2846
+ }, /*#__PURE__*/React.createElement(Components.Text, {
2847
+ type: "formTitleLarge",
2848
+ className: "marginBottom-24"
2849
+ }, this.state.infoId == null ? 'New' : 'Edit', " Request"), /*#__PURE__*/React.createElement(Components.GenericInput, {
2850
+ id: "userName",
2962
2851
  type: "text",
2963
- label: "Request type title",
2964
- placeholder: "Request type title",
2965
- value: jobTypeName,
2966
- onChange: this.onHandleChange,
2852
+ label: "Name",
2853
+ placeholder: "Insert name here",
2854
+ value: this.state.userName,
2855
+ onChange: function onChange(e) {
2856
+ return _this4.onHandleChange(e);
2857
+ },
2967
2858
  isRequired: true,
2859
+ alwaysShowLabel: true,
2968
2860
  isValid: function isValid() {
2969
- return !_.isEmpty(jobTypeName);
2861
+ return !_.isEmpty(_this4.state.userName);
2970
2862
  },
2971
2863
  showError: function showError() {
2972
- return showWarnings && _.isEmpty(jobTypeName);
2864
+ return _this4.state.showWarnings && _.isEmpty(_this4.state.userName);
2865
+ }
2866
+ }), /*#__PURE__*/React.createElement(Components.GenericInput, {
2867
+ id: "room",
2868
+ type: "text",
2869
+ label: "Location",
2870
+ placeholder: "Insert address here",
2871
+ value: this.state.room,
2872
+ onChange: function onChange(e) {
2873
+ return _this4.onHandleChange(e);
2973
2874
  },
2974
- alwaysShowLabel: true
2875
+ isRequired: true,
2876
+ alwaysShowLabel: true,
2877
+ isValid: function isValid() {
2878
+ return !_.isEmpty(_this4.state.room);
2879
+ },
2880
+ showError: function showError() {
2881
+ return _this4.state.showWarnings && _.isEmpty(_this4.state.room);
2882
+ }
2975
2883
  }), /*#__PURE__*/React.createElement(Components.GenericInput, {
2976
- id: "jobTypeEmail",
2884
+ id: "phone",
2977
2885
  type: "text",
2978
- label: "Email",
2979
- placeholder: "Request email",
2980
- help: "This is the email address that'll receive service requests of this type",
2981
- value: jobTypeEmail,
2982
- onChange: this.onHandleChange,
2886
+ label: "Contact number",
2887
+ placeholder: "04XX XXX XXX",
2888
+ value: this.state.phone // showError={this.state.showWarnings && !this.validateImage()}
2889
+ ,
2890
+ onChange: function onChange(e) {
2891
+ return _this4.onHandleChange(e);
2892
+ },
2893
+ alwaysShowLabel: true
2894
+ }), /*#__PURE__*/React.createElement("div", {
2895
+ style: {
2896
+ marginBottom: 15
2897
+ }
2898
+ }, /*#__PURE__*/React.createElement(Components.Text, {
2899
+ type: "formLabel"
2900
+ }, "Job Type"), /*#__PURE__*/React.createElement(DropdownButton, {
2901
+ style: {
2902
+ minWidth: 80
2903
+ },
2904
+ bsStyle: "default",
2905
+ title: this.state.type,
2906
+ id: "typeSelect",
2907
+ onSelect: this.onSelectType
2908
+ }, this.renderTypeOptions())), /*#__PURE__*/React.createElement(Components.GenericInput, {
2909
+ id: "title",
2910
+ label: "Title for the work required",
2911
+ type: "textarea",
2912
+ placeholder: "Title for the work required",
2913
+ value: this.state.title,
2914
+ onChange: function onChange(e) {
2915
+ return _this4.onHandleChange(e);
2916
+ },
2917
+ inputStyle: {
2918
+ height: 80
2919
+ },
2983
2920
  isRequired: true,
2984
- isValid: this.validateEmail,
2921
+ isValid: function isValid() {
2922
+ return !_.isEmpty(_this4.state.title);
2923
+ },
2985
2924
  showError: function showError() {
2986
- return showWarnings && !_this5.validateEmail();
2925
+ return _this4.state.showWarnings && _.isEmpty(_this4.state.title);
2987
2926
  },
2988
2927
  alwaysShowLabel: true
2989
2928
  }), /*#__PURE__*/React.createElement(Components.GenericInput, {
2990
- id: "jobTypeDescription",
2991
- type: "text",
2992
- label: "Description",
2993
- placeholder: "Add a description. ",
2994
- help: "This description will be visible to the people to help them select the correct request type.",
2995
- value: jobTypeDescription,
2996
- onChange: this.onHandleChange,
2929
+ id: "description",
2930
+ label: "Description of work required",
2931
+ type: "textarea",
2932
+ placeholder: "Description of work required",
2933
+ value: this.state.description,
2934
+ onChange: function onChange(e) {
2935
+ return _this4.onHandleChange(e);
2936
+ },
2937
+ inputStyle: {
2938
+ height: 80
2939
+ },
2940
+ alwaysShowLabel: true
2941
+ }), /*#__PURE__*/React.createElement(Components.RadioButton, {
2942
+ label: "Person must be home during work?",
2943
+ isActive: this.state.isHome,
2944
+ options: [{
2945
+ Label: 'No',
2946
+ Value: false,
2947
+ onChange: function onChange() {
2948
+ return _this4.setState({
2949
+ isHome: false
2950
+ });
2951
+ }
2952
+ }, {
2953
+ Label: 'Yes',
2954
+ Value: true,
2955
+ onChange: function onChange() {
2956
+ return _this4.setState({
2957
+ isHome: true
2958
+ });
2959
+ }
2960
+ }]
2961
+ }), this.state.isHome && /*#__PURE__*/React.createElement(Components.GenericInput, {
2962
+ style: {
2963
+ marginTop: 16
2964
+ },
2965
+ label: "Description of person's available times",
2966
+ id: "homeText",
2967
+ type: "textarea",
2968
+ placeholder: "Description of person's available times",
2969
+ value: this.state.homeText,
2970
+ onChange: function onChange(e) {
2971
+ return _this4.onHandleChange(e);
2972
+ },
2973
+ inputStyle: {
2974
+ height: 80
2975
+ },
2997
2976
  isRequired: true,
2998
2977
  isValid: function isValid() {
2999
- return !_.isEmpty(jobTypeDescription);
2978
+ return !_.isEmpty(_this4.state.homeText);
3000
2979
  },
3001
2980
  showError: function showError() {
3002
- return showWarnings && _.isEmpty(jobTypeDescription);
2981
+ return _this4.state.showWarnings && _.isEmpty(_this4.state.homeText);
3003
2982
  },
3004
2983
  alwaysShowLabel: true
3005
- }));
2984
+ })));
3006
2985
  }
3007
2986
  }, {
3008
2987
  key: "render",
3009
2988
  value: function render() {
3010
- return /*#__PURE__*/React.createElement("div", {
3011
- className: "hub-wrapperContainer"
3012
- }, /*#__PURE__*/React.createElement("div", {
3013
- className: "hub-headerContentWrapper"
3014
- }, /*#__PURE__*/React.createElement(Components.Header, null), /*#__PURE__*/React.createElement("div", {
3015
- className: "hub-contentWrapper",
3016
- style: {
3017
- position: 'relative'
3018
- }
3019
- }, this.renderJobTypes()), this.renderNewUserTypePopup(), /*#__PURE__*/React.createElement("div", {
3020
- className: "hub_tidioPadding"
3021
- })));
2989
+ var success = this.state.success;
2990
+ return /*#__PURE__*/React.createElement(Components.OverlayPage, null, /*#__PURE__*/React.createElement(Components.OverlayPageContents, {
2991
+ noBottomButtons: success
2992
+ }, /*#__PURE__*/React.createElement(Components.OverlayPageSection, {
2993
+ className: "pageSectionWrapper--newPopup"
2994
+ }, /*#__PURE__*/React.createElement("div", null, this.renderSuccess(), !success && this.renderMain()))), /*#__PURE__*/React.createElement(Components.OverlayPageBottomButtons, null, this.renderSubmit()));
3022
2995
  }
3023
2996
  }]);
3024
2997
 
3025
- return JobTypes;
2998
+ return AddJob;
3026
2999
  }(Component);
3027
3000
 
3028
3001
  var mapStateToProps = function mapStateToProps(state) {
3029
- var jobtypes = state.maintenance.jobtypes;
3030
3002
  var auth = state.auth;
3031
3003
  return {
3032
- jobtypes: jobtypes,
3033
3004
  auth: auth
3034
3005
  };
3035
3006
  };
3036
3007
 
3037
- var JobTypes$1 = connect(mapStateToProps, {
3038
- jobTypesLoaded: jobTypesLoaded,
3039
- jobTypesUpdate: jobTypesUpdate
3040
- })(withRouter(JobTypes));
3008
+ var AddJob$1 = connect(mapStateToProps, {
3009
+ jobsUpdate: jobsUpdate,
3010
+ jobsLoaded: jobsLoaded,
3011
+ addRecentlyCreated: Actions.addRecentlyCreated
3012
+ })(withRouter(AddJob));
3041
3013
 
3042
3014
  function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
3043
3015
 
@@ -3432,8 +3404,7 @@ var Reducers = {
3432
3404
  var Screens = {
3433
3405
  RequestsHub: RequestsHub$1,
3434
3406
  Job: Job$1,
3435
- AddJob: AddJob$1,
3436
- JobTypes: JobTypes$1
3407
+ AddJob: AddJob$1
3437
3408
  };
3438
3409
 
3439
3410
  export { ActivityText, FeatureConfig as Config, PreviewFull, PreviewGrid, PreviewWidget, Reducers, Screens, ViewFull, ViewWidget };