@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
37 lines • 1.63 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect } from 'react';
import { useCreateCompanyMutation } from '../../redux/api/company-api';
import { toast } from 'react-toastify';
import { CompanyCreated } from './components/company-created';
import { Container } from '../login.page/login.page.styles';
import { CreateCompany } from './components/create-company';
var CreateCompanyPage = function () {
// 👇 Calling the Register Mutation
var _a = useCreateCompanyMutation(), createCompany = _a[0], _b = _a[1], isLoading = _b.isLoading, isSuccess = _b.isSuccess, error = _b.error, isError = _b.isError, data = _b.data;
useEffect(function () {
if (isSuccess) {
toast.success(data === null || data === void 0 ? void 0 : data.message);
}
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 onSubmitHandler = function (values) {
createCompany(values);
};
return (_jsx(Container, { children: !data ? (_jsx(CreateCompany, { onSubmit: onSubmitHandler })) : (_jsx(CompanyCreated, { data: data })) }));
};
export { CreateCompanyPage };
//# sourceMappingURL=create-company.page.js.map