diff --git a/__app/component/WhatsappShare/README.md b/__app/component/WhatsappShare/README.md new file mode 100644 index 0000000..ee8a906 --- /dev/null +++ b/__app/component/WhatsappShare/README.md @@ -0,0 +1,43 @@ +## 1. Happy Flow +#### a) Passing child + + + + +## 2. Success: successCb callBack Fn along with success msg + + + + + +> [!Note] +> **successCb** will get an object contains the property **msgType**, **msg**, **data** + +## 3. Failure: failureCb callBack Fn along with failure msg + + + + + +> [!Note] +> **failureCb** will get an object contains the property **msgType**, **msg** + +> [!Important] +Failure can happend due to multiple reasons, due to that reason **failureMsg** is an object having different kind of error property according to the error can occur in component + +## 4. Failure: Device don't support the feature and you want to hide the feauture from User + + + + + +> [!Note] +> if **showForever** props value is false, feature will be hidden in case of unSupported by the device + +## 5. Combine with all props + + + + + + \ No newline at end of file diff --git a/__app/component/WhatsappShare/WhatsappShare.js b/__app/component/WhatsappShare/WhatsappShare.js new file mode 100644 index 0000000..b44feaf --- /dev/null +++ b/__app/component/WhatsappShare/WhatsappShare.js @@ -0,0 +1,69 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { handleSuccess, handleError } from '../services/handlerService'; +import Wrapper from '../Wrapper/Wrapper'; + +const failureMsgDefault = { + unSupported: 'WhatsappShare is not supporting in your device', + badRequest: 'msg is missing', + error: 'Unable to fetch details from WhatsappShare', +}; + +function WhatsappShare({ + successCb, + failureCb, + successMsg, + failureMsg: failureMsgProps, + children, + mobile, + msg, +}) { + const failureMsg = { ...failureMsgDefault, ...failureMsgProps }; + + const getWhatsappShare = () => { + if (mobile) { + window.location.href = `https://wa.me/${mobile}/?text=${msg}`; + handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: msg }); + } else if (msg) { + window.location.href = `https://wa.me/?text=${msg}`; + handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: msg }); + } else { + return handleError({ msgType: 'BAD_REQUEST', msg: failureMsg.badRequest, failureCb }); + } + + return true; + }; + + return ( +