|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import { useState } from 'react'; |
| 21 | +import { Modal, Button, Form } from 'react-bootstrap'; |
| 22 | +import { useTranslation } from 'react-i18next'; |
| 23 | + |
| 24 | +import { changeUserStatus } from '@/services'; |
| 25 | +import { SUSPENSE_USER_TIME } from '@/common/constants'; |
| 26 | +import { toastStore } from '@/stores'; |
| 27 | + |
| 28 | +const SuspenseUserModal = ({ show, userId, onClose, refreshUsers }) => { |
| 29 | + const { t } = useTranslation('translation', { keyPrefix: 'admin.users' }); |
| 30 | + const [checkVal, setCheckVal] = useState('forever'); |
| 31 | + |
| 32 | + const handleClose = () => { |
| 33 | + onClose(); |
| 34 | + setCheckVal('forever'); |
| 35 | + }; |
| 36 | + |
| 37 | + const handleSubmit = (e) => { |
| 38 | + e.preventDefault(); |
| 39 | + changeUserStatus({ |
| 40 | + user_id: userId, |
| 41 | + status: 'suspended', |
| 42 | + suspend_duration: checkVal, |
| 43 | + }).then(() => { |
| 44 | + toastStore.getState().show({ |
| 45 | + msg: t('user_suspended', { keyPrefix: 'messages' }), |
| 46 | + variant: 'success', |
| 47 | + }); |
| 48 | + refreshUsers?.(); |
| 49 | + handleClose(); |
| 50 | + }); |
| 51 | + }; |
| 52 | + |
| 53 | + return ( |
| 54 | + <Modal show={show} onHide={handleClose}> |
| 55 | + <Modal.Header closeButton> |
| 56 | + <Modal.Title>{t('suspend_user.title')}</Modal.Title> |
| 57 | + </Modal.Header> |
| 58 | + <Modal.Body> |
| 59 | + <p>{t('suspend_user.content')}</p> |
| 60 | + <Form> |
| 61 | + <Form.Group controlId="delete_user" className="mb-3"> |
| 62 | + <Form.Label>{t('suspend_user.label')}</Form.Label> |
| 63 | + <Form.Select |
| 64 | + value={checkVal} |
| 65 | + onChange={(e) => setCheckVal(e.target.value)}> |
| 66 | + <option value="forever">{t('suspend_user.forever')}</option> |
| 67 | + {SUSPENSE_USER_TIME.map((item) => { |
| 68 | + return ( |
| 69 | + <option key={item.value} value={item.value}> |
| 70 | + {item.time} {t(item.label, { keyPrefix: 'dates' })} |
| 71 | + </option> |
| 72 | + ); |
| 73 | + })} |
| 74 | + </Form.Select> |
| 75 | + </Form.Group> |
| 76 | + </Form> |
| 77 | + </Modal.Body> |
| 78 | + <Modal.Footer> |
| 79 | + <Button variant="link" onClick={handleClose}> |
| 80 | + {t('cancel', { keyPrefix: 'btns' })} |
| 81 | + </Button> |
| 82 | + <Button variant="danger" onClick={handleSubmit}> |
| 83 | + {t('suspend', { keyPrefix: 'btns' })} |
| 84 | + </Button> |
| 85 | + </Modal.Footer> |
| 86 | + </Modal> |
| 87 | + ); |
| 88 | +}; |
| 89 | + |
| 90 | +export default SuspenseUserModal; |
0 commit comments