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

38 lines 2.52 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 { useCreateProjectMutation } from '../../redux/api/project-api'; import { Button, Form, Input, Modal } from 'antd'; var CreateProjectModal = function (_a) { var Trigger = _a.Trigger; var _b = useState(false), isOpen = _b[0], setIsOpen = _b[1]; var _c = useCreateProjectMutation(), createProject = _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) { createProject(values); }; return (_jsxs(_Fragment, { children: [_jsx(Trigger, { onClick: function () { return setIsOpen(true); } }), _jsx(Modal, __assign({ title: "Create 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: { remember: true }, 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: "Create" })), _jsx(Button, __assign({ type: "link", onClick: function () { return setIsOpen(false); } }, { children: "Cancel" }))] }))] })) }))] })); }; export { CreateProjectModal }; //# sourceMappingURL=create-project.js.map