summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/containers/modals/EditRackNameModal.js
blob: edb57217080731d91379aa020f3fe516964e48e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { closeEditRackNameModal } from '../../actions/modals/topology'
import { editRackName } from '../../actions/topology/rack'
import TextInputModal from '../../components/modals/TextInputModal'

const EditRackNameModal = (props) => {
    const { visible, previousName } = useSelector((state) => {
        return {
            visible: state.modals.editRackNameModalVisible,
            previousName:
                state.interactionLevel.mode === 'RACK'
                    ? state.objects.rack[state.objects.tile[state.interactionLevel.tileId].rackId].name
                    : '',
        }
    })

    const dispatch = useDispatch()
    const callback = (name) => {
        if (name) {
            dispatch(editRackName(name))
        }
        dispatch(closeEditRackNameModal())
    }
    return (
        <TextInputModal
            title="Edit rack name"
            label="Rack name"
            show={visible}
            initialValue={previousName}
            callback={callback}
            {...props}
        />
    )
}

export default EditRackNameModal