UNPKG

@rtbjs/use-state

Version:

`@rtbjs/use-state` is a state management tool that can act as a local state and be easily turned into a global redux state. It is an innovative approach to state management that combines the advantages of both React's useState and Redux's state management

41 lines 2.72 kB
import { __assign } from "tslib"; import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useEffect, useState } from 'react'; import { toast } from 'react-toastify'; import { useUpdateProjectMutation } from '../../redux/api/project-api'; import { Button, Form, Input, Modal } from 'antd'; var UpdateProjectModal = function (_a) { var Trigger = _a.Trigger, project = _a.project; var _b = useState(false), isOpen = _b[0], setIsOpen = _b[1]; var _c = useUpdateProjectMutation(), updateProject = _c[0], _d = _c[1], isLoading = _d.isLoading, isError = _d.isError, error = _d.error, isSuccess = _d.isSuccess; useEffect(function () { if (isSuccess) { toast.success('Project updated successfully'); setIsOpen(false); } if (isError) { if (Array.isArray(error.data.error)) { error.data.error.forEach(function (el) { return toast.error(el.message, { position: 'top-right' }); }); } else { toast.error(error.data.message, { position: 'top-right' }); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [isLoading]); var onFinish = function (values) { updateProject({ id: project === null || project === void 0 ? void 0 : project.id, project: values }); }; return (_jsxs(_Fragment, { children: [_jsx(Trigger, { onClick: function () { return setIsOpen(true); } }), _jsx(Modal, __assign({ title: "Edit project", open: isOpen, footer: null, destroyOnClose: true, onCancel: function () { return setIsOpen(false); } }, { children: _jsxs(Form, __assign({ name: "basic", labelCol: { span: 8 }, wrapperCol: { span: 16 }, style: { maxWidth: 600 }, initialValues: { name: project.name, description: project.description }, onFinish: onFinish, autoComplete: "off" }, { children: [_jsx(Form.Item, __assign({ label: "Name", name: "name", rules: [{ required: true, message: 'Please input the name' }] }, { children: _jsx(Input, {}) })), _jsx(Form.Item, __assign({ label: "Description", name: "description" }, { children: _jsx(Input.TextArea, {}) })), _jsxs(Form.Item, __assign({ wrapperCol: { offset: 8, span: 16 } }, { children: [_jsx(Button, __assign({ type: "primary", htmlType: "submit" }, { children: "Save" })), _jsx(Button, __assign({ type: "link", onClick: function () { return setIsOpen(false); } }, { children: "Cancel" }))] }))] })) }))] })); }; export { UpdateProjectModal }; //# sourceMappingURL=update-project.js.map