Skip to content

Commit

Permalink
feat(whatsapp share): whatsapp share component has been added success…
Browse files Browse the repository at this point in the history
…fully
  • Loading branch information
opensrc0 committed Apr 9, 2024
1 parent 607e4e5 commit a80375f
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
43 changes: 43 additions & 0 deletions __app/component/WhatsappShare/README.md
Original file line number Diff line number Diff line change
@@ -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






69 changes: 69 additions & 0 deletions __app/component/WhatsappShare/WhatsappShare.js
Original file line number Diff line number Diff line change
@@ -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 (
<div>
{React.Children.map(children || 'Whatsapp Share', (child) => React.cloneElement(
typeof child === 'string' ? <span>{child}</span> : child,
{
onClick: getWhatsappShare,
},
))}
</div>
);
}

WhatsappShare.isBrowserSupport = () => globalThis && true;

WhatsappShare.propTypes = {
successCb: PropTypes.func,
failureCb: PropTypes.func,
successMsg: PropTypes.string,
failureMsg: PropTypes.object,
mobile: PropTypes.number,
msg: PropTypes.string,
};

WhatsappShare.defaultProps = {
successCb: () => {},
failureCb: () => {},
successMsg: 'WhatsappShare details fetch Successfully',
failureMsg: { ...failureMsgDefault },
mobile: '',
msg: '',
};

export default Wrapper(WhatsappShare);
5 changes: 5 additions & 0 deletions __app/component/WhatsappShare/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import WhatsappShare from './WhatsappShare';

export { WhatsappShare };

export default WhatsappShare;
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"detectmylocation",
"colorpicker",
"wakelock",
"ABCKEFG"
"WhatsappShare"
],
"config": {
"commitizen": {
Expand Down Expand Up @@ -98,7 +98,8 @@
"TextToSpeech/",
"VoiceRecognition/",
"Vibrate/",
"ColorPicker/"
"ColorPicker/",
"WhatsappShare/"
],
"devDependencies": {
"@babel/cli": "^7.23.9",
Expand Down

0 comments on commit a80375f

Please sign in to comment.