|
| 1 | +/* |
| 2 | + * . .o8 oooo |
| 3 | + * .o8 "888 `888 |
| 4 | + * .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo |
| 5 | + * 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' |
| 6 | + * 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. |
| 7 | + * 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. |
| 8 | + * "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o |
| 9 | + * ======================================================================== |
| 10 | + * Author: Chris Brame |
| 11 | + * Updated: 6/21/23 11:59 AM |
| 12 | + * Copyright (c) 2014-2023. All rights reserved. |
| 13 | + */ |
| 14 | + |
| 15 | +import React from 'react' |
| 16 | +import PropTypes from 'prop-types' |
| 17 | +import { connect } from 'react-redux' |
| 18 | +import { fetchTicketStatus, deleteStatus } from 'actions/tickets' |
| 19 | +import BaseModal from './BaseModal' |
| 20 | +import Button from 'components/Button' |
| 21 | +import SingleSelect from 'components/SingleSelect' |
| 22 | + |
| 23 | +import helpers from 'lib/helpers' |
| 24 | + |
| 25 | +class DeleteTicketStatusModal extends React.Component { |
| 26 | + constructor (props) { |
| 27 | + super(props) |
| 28 | + this.state = { |
| 29 | + selectedStatus: '' |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + componentDidMount () {} |
| 34 | + |
| 35 | + getTicketStatuses () { |
| 36 | + return this.props.settings && this.props.settings.get('status') ? this.props.settings.get('status').toArray() : [] |
| 37 | + } |
| 38 | + |
| 39 | + onSelectChanged (e) { |
| 40 | + this.setState({ |
| 41 | + selectedStatus: e.target.value |
| 42 | + }) |
| 43 | + } |
| 44 | + |
| 45 | + onFormSubmit (e) { |
| 46 | + e.preventDefault() |
| 47 | + if (!this.state.selectedStatus) { |
| 48 | + helpers.UI.showSnackbar('Unable to get new ticket status. Aborting...', true) |
| 49 | + return true |
| 50 | + } |
| 51 | + |
| 52 | + this.props.deleteStatus({ id: this.props.status.get('_id'), newStatusId: this.state.selectedStatus }) |
| 53 | + } |
| 54 | + |
| 55 | + render () { |
| 56 | + const { status } = this.props |
| 57 | + const mappedStatuses = this.getTicketStatuses() |
| 58 | + .filter(obj => { |
| 59 | + return status.get('name') !== obj.get('name') |
| 60 | + }) |
| 61 | + .map(item => { |
| 62 | + return { text: item.get('name'), value: item.get('_id') } |
| 63 | + }) |
| 64 | + return ( |
| 65 | + <BaseModal {...this.props} options={{ bgclose: false }}> |
| 66 | + <form className={'uk-form-stacked'} onSubmit={e => this.onFormSubmit(e)}> |
| 67 | + <div className='uk-margin-medium-bottom uk-clearfix'> |
| 68 | + <h2>Remove Ticket Status</h2> |
| 69 | + <span> |
| 70 | + Please select the ticket status you wish to reassign tickets to in order to delete this ticket status. |
| 71 | + </span> |
| 72 | + </div> |
| 73 | + <div className='uk-margin-medium-bottom uk-clearfix'> |
| 74 | + <div className='uk-float-left' style={{ width: '100%' }}> |
| 75 | + <label className={'uk-form-label nopadding nomargin'}>Status</label> |
| 76 | + <SingleSelect |
| 77 | + showTextbox={false} |
| 78 | + items={mappedStatuses} |
| 79 | + onSelectChange={e => this.onSelectChanged(e)} |
| 80 | + value={this.state.selectedStatus} |
| 81 | + /> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + <div className='uk-margin-medium-bottom uk-clearfix'> |
| 85 | + <span className='uk-text-danger'> |
| 86 | + WARNING: This will change all tickets with status <strong>{status.get('name')}</strong> to the selected |
| 87 | + ticket status. |
| 88 | + <br /> |
| 89 | + <strong>This is permanent!</strong> |
| 90 | + </span> |
| 91 | + </div> |
| 92 | + <div className='uk-modal-footer uk-text-right'> |
| 93 | + <Button text={'Cancel'} flat={true} waves={true} extraClass={'uk-modal-close'} /> |
| 94 | + <Button text={'Delete'} style={'danger'} flat={true} type={'submit'} /> |
| 95 | + </div> |
| 96 | + </form> |
| 97 | + </BaseModal> |
| 98 | + ) |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +DeleteTicketStatusModal.propTypes = { |
| 103 | + status: PropTypes.object.isRequired, |
| 104 | + settings: PropTypes.object.isRequired, |
| 105 | + deleteStatus: PropTypes.func.isRequired, |
| 106 | + fetchTicketStatus: PropTypes.func.isRequired |
| 107 | +} |
| 108 | + |
| 109 | +const mapStateToProps = state => ({ |
| 110 | + settings: state.settings.settings, |
| 111 | + ticketStatuses: state.ticketsState.ticketStatuses |
| 112 | +}) |
| 113 | + |
| 114 | +export default connect(mapStateToProps, { fetchTicketStatus, deleteStatus })(DeleteTicketStatusModal) |
0 commit comments