reactstrap-react-lib
Advanced tools
Comparing version
@@ -68,3 +68,3 @@ "use strict"; | ||
(_a = modRef.current) === null || _a === void 0 ? void 0 : _a.close(); | ||
} }), | ||
}, modelTitle: "Do you want delete data ?", modelText: "Press Ok to delete data from server \n Press cancel to exit" }), | ||
react_1.default.createElement(reactstrap_1.Form, { onSubmit: (e) => { | ||
@@ -71,0 +71,0 @@ var _a; |
@@ -30,5 +30,11 @@ import { AxiosError, AxiosResponse } from 'axios'; | ||
errorCallback?: (...arg: any) => any; | ||
/** | ||
* This function is for validation before submitting inthe front end itself | ||
* in case of failed validadtion return string | ||
* If validation did succeed return "" | ||
*/ | ||
validation?: () => string; | ||
} | ||
declare const FormSubmit: ({ curObj, curUri, Inputs, reset, onSuccess, onError, successCallBack, errorCallback }: Props) => JSX.Element; | ||
declare const FormSubmit: ({ curObj, curUri, Inputs, reset, onSuccess, onError, successCallBack, errorCallback, validation }: Props) => JSX.Element; | ||
export default FormSubmit; | ||
//# sourceMappingURL=FormSubmit.d.ts.map |
@@ -40,8 +40,9 @@ "use strict"; | ||
const ModelP_1 = __importDefault(require("../ModelP")); | ||
const FormSubmit = ({ curObj, curUri, Inputs, reset, onSuccess, onError, successCallBack, errorCallback }) => { | ||
const FormSubmit = ({ curObj, curUri, Inputs, reset, onSuccess, onError, successCallBack, errorCallback, validation = () => "" }) => { | ||
const butRef = react_1.useRef(null); | ||
const modRef = react_1.useRef(null); | ||
const alerRef = react_1.useRef(null); | ||
const submitHandle = (_curUri, _curObj, _onSuccess, _onError) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
const submitHandle = (_curUri, _curObj, _onSuccess, _onError, _validation) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
let validationErrorMessage = ""; | ||
try { | ||
@@ -51,11 +52,17 @@ (_a = modRef.current) === null || _a === void 0 ? void 0 : _a.close(); | ||
(_c = alerRef.current) === null || _c === void 0 ? void 0 : _c.alertLight(); | ||
validationErrorMessage = _validation(); | ||
if (validationErrorMessage !== "") { | ||
(_d = alerRef.current) === null || _d === void 0 ? void 0 : _d.alertError(validationErrorMessage); | ||
(_e = butRef.current) === null || _e === void 0 ? void 0 : _e.hideSpin(); | ||
return; | ||
} | ||
let res = yield axios_1.default.post(_curUri, _curObj).then(res => res); | ||
let _successMessage = _onSuccess(res, successCallBack); | ||
(_d = butRef.current) === null || _d === void 0 ? void 0 : _d.hideSpin(); | ||
(_e = alerRef.current) === null || _e === void 0 ? void 0 : _e.alertSuccess(_successMessage); | ||
(_f = butRef.current) === null || _f === void 0 ? void 0 : _f.hideSpin(); | ||
(_g = alerRef.current) === null || _g === void 0 ? void 0 : _g.alertSuccess(_successMessage); | ||
} | ||
catch (error) { | ||
let _errorMessage = _onError(error, errorCallback); | ||
(_f = alerRef.current) === null || _f === void 0 ? void 0 : _f.alertError(_errorMessage); | ||
(_g = butRef.current) === null || _g === void 0 ? void 0 : _g.hideSpin(); | ||
(_h = alerRef.current) === null || _h === void 0 ? void 0 : _h.alertError(_errorMessage); | ||
(_j = butRef.current) === null || _j === void 0 ? void 0 : _j.hideSpin(); | ||
} | ||
@@ -68,5 +75,5 @@ }); | ||
var _a; | ||
submitHandle(curUri, curObj, onSuccess, onError); | ||
submitHandle(curUri, curObj, onSuccess, onError, validation); | ||
(_a = modRef.current) === null || _a === void 0 ? void 0 : _a.close(); | ||
} }), | ||
}, modelText: "Press Ok to Submit data to server \\n Press cancel to exit", modelTitle: "Do you wan t submit Data ?" }), | ||
react_1.default.createElement(reactstrap_1.Form, { onSubmit: (e) => { | ||
@@ -73,0 +80,0 @@ var _a; |
import { Component } from 'react'; | ||
interface Props { | ||
/** | ||
* e is event | ||
*/ | ||
Ok: (e: any) => void; | ||
/** | ||
* text to bedisplayes in body of modal | ||
*/ | ||
modelText: string; | ||
/** | ||
* title of model | ||
*/ | ||
modelTitle: string; | ||
} | ||
@@ -5,0 +16,0 @@ interface State { |
@@ -39,3 +39,3 @@ "use strict"; | ||
*/ | ||
this.show = (curText = "Do you want Submit this data", curTitle = "Data Submission") => { | ||
this.show = (curText = this.props.modelText, curTitle = this.props.modelTitle) => { | ||
this.setState(Object.assign(Object.assign({}, this.state), { modal: true, text: curText, title: curTitle })); | ||
@@ -42,0 +42,0 @@ }; |
{ | ||
"name": "reactstrap-react-lib", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "This is a lib for react and next", | ||
@@ -8,3 +8,4 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"build": "tsc -p ." | ||
"build": "tsc -p .", | ||
"dev": "npm run build && echo Built the lib \\n && yalc publish && echo Published to local repo \\n && cd next-app && echo Now inside next-app \\n && yalc update && echo Update from local repo \\n && npm run dev" | ||
}, | ||
@@ -11,0 +12,0 @@ "repository": { |
@@ -11,1 +11,11 @@ # reactstrap-react-lib | ||
5. FormDelete | ||
## FormSubmit | ||
This is for submiting data to server. it has inbuilt submit button and also reset button. | ||
1. declare states as {} your component asign it curObj prop | ||
2. asign your form submission uri to curUri prop | ||
3. onSuccess prop is function which has two arguments first one is response from server and secons one is succusscalback function | ||
4. onError prop is function which has two arguments first one is response from server and second one is Errorcalback function | ||
5. successCalback is prop which has to passed in onSuccess function | ||
6. errorCalback is prop which has to passed in onError function | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
69248
5.46%1144
4.76%21
90.91%