Skip to content

Commit

Permalink
fix(failuremsgdefault): changed failureMsgDefault accross the component
Browse files Browse the repository at this point in the history
  • Loading branch information
opensrc0 committed Apr 6, 2024
1 parent afb5630 commit d64ab7b
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Node.js CI

on:
push:
branches: [ "main" ]
branches: [ "master" ]
pull_request:
branches: '*'

Expand Down
19 changes: 14 additions & 5 deletions __app/component/AutoFillOtp/AutoFillOtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ const abortAutoFill = (abort, time) => {
}, time * 60 * 1000);
};

const defaultProps = {
successCb: (() => {}),
failureCb: (() => {}),
successMsg: 'OTP autofilled successfully',
failureMsg: {
UN_SUPPORTED_FEATURE: 'Your device is not supporting AutofillOTP',
ERROR: '',
},
};
function AutoFillOtp(props = {}) {
const successCb = props.successCb || (() => {});
const failureCb = props.failureCb || (() => {});
const successMsg = props.successMsg || '';
const failureMsg = props.failureMsg || {};
const successCb = props.successCb || defaultProps.successCb;
const failureCb = props.failureCb || defaultProps.failureCb;
const successMsg = props.successMsg || defaultProps.successMsg;
const failureMsg = { ...defaultProps.failureMsg, ...props.failureMsg };

if (AutoFillOtp.isBrowserSupport()) {
const abort = new AbortController();
Expand All @@ -24,7 +33,7 @@ function AutoFillOtp(props = {}) {
handleSuccess({ msgType: 'SUCCESSFUL', msg: successMsg, successCb, data: code });
}).catch((error) => handleError({ msgType: 'ERROR', msg: error, failureCb }));
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported || 'Your device is not supporting AutofillOTP', failureCb });
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
}
}

Expand Down
14 changes: 9 additions & 5 deletions __app/component/ColorPicker/ColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import PropTypes from 'prop-types';
import { handleSuccess, handleError } from '../services/handlerService';
import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'Your browser does not support the Color Picker fetaure',
error: 'Unable to copy color code',
};

function ColorPicker({
successCb,
failureCb,
successMsg,
failureMsg,
failureMsg: failureMsgProps,
children,
}) {
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };

const pickColor = () => {
if (ColorPicker.isBrowserSupport()) {
const eyeDropper = new globalThis.EyeDropper();
Expand Down Expand Up @@ -45,10 +52,7 @@ ColorPicker.defaultProps = {
successCb: () => {},
failureCb: () => {},
successMsg: 'Color copied successfully!!',
failureMsg: {
unSupported: 'Your browser does not support the Color Picker fetaure',
error: 'Unable to copy color code',
},
failureMsg: { ...failureMsgDefault },
};

export default Wrapper(ColorPicker);
14 changes: 9 additions & 5 deletions __app/component/CopyToClipboard/CopyToClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ import PropTypes from 'prop-types';
import { handleSuccess, handleError, handleLoading } from '../services/handlerService';
import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'Copy To ClipBoard is not supporting in your device',
error: 'Unable to copy',
};

function CopyToClipboard({
successCb,
failureCb,
loadingCb,
successMsg,
failureMsg,
failureMsg: failureMsgProps,
children,
elementToBeCopy,
}) {
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };

const copyText = () => {
if (CopyToClipboard.isBrowserSupport()) {
handleLoading({ loadingCb });
Expand Down Expand Up @@ -45,10 +52,7 @@ CopyToClipboard.defaultProps = {
failureCb: () => {},
loadingCb: () => {},
successMsg: 'Copied Successfully',
failureMsg: {
unSupported: 'Copy To ClipBoard is not supporting in your device',
error: 'Unable to copy',
},
failureMsg: { ...failureMsgDefault },
};

export default Wrapper(CopyToClipboard);
28 changes: 12 additions & 16 deletions __app/component/FaceDetector/FaceDetectorInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ const failureMsgDefault = {
};

function FaceDetectorInit({
successCb,
// successCb,
failureCb,
loadingCb,
successMsg,
failureMsg,
// successMsg,
failureMsg: failureMsgProps,
cameraType,
zIndex,
children,
}) {
const failureMsgMerge = { ...failureMsgDefault, ...failureMsg };
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };
let list = null;
let video = null;
let facingMode;
Expand Down Expand Up @@ -63,7 +63,7 @@ function FaceDetectorInit({
// clearTimeout(unmoutRenderLoop);
}
} catch (error) {
return handleError({ msgType: 'BAR_CODE_DETECTION_FAILED', msg: failureMsgMerge.barCodeDetectionFailed || JSON.stringify(error), failureCb });
return handleError({ msgType: 'BAR_CODE_DETECTION_FAILED', msg: failureMsg.barCodeDetectionFailed || JSON.stringify(error), failureCb });
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ function FaceDetectorInit({
},
});
} catch (error) {
return handleError({ msgType: 'STREAMING_FAILED', msg: failureMsgMerge.streamingFailed || JSON.stringify(error), failureCb });
return handleError({ msgType: 'STREAMING_FAILED', msg: failureMsg.streamingFailed || JSON.stringify(error), failureCb });
}
return mediaStream;
};
Expand All @@ -131,7 +131,7 @@ function FaceDetectorInit({
});
setFlash((s) => !s);
} catch (error) {
return handleError({ msgType: 'FLASH_UPSUPPORTED', msg: failureMsgMerge.flashUnsupported, failureCb });
return handleError({ msgType: 'FLASH_UPSUPPORTED', msg: failureMsg.flashUnsupported, failureCb });
}
return true;
};
Expand All @@ -152,7 +152,7 @@ function FaceDetectorInit({

startVideo();
} else {
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsgMerge.unSupported, failureCb });
return handleError({ msgType: 'UN_SUPPORTED_FEATURE', msg: failureMsg.unSupported, failureCb });
}

return true;
Expand All @@ -176,10 +176,6 @@ function FaceDetectorInit({
allClear,
toggleCamera,
toggleFlash,
successCb,
successMsg,
failureCb,
failureMsg,
}))
}
{
Expand All @@ -206,20 +202,20 @@ function FaceDetectorInit({
FaceDetectorInit.isBrowserSupport = () => navigator?.mediaDevices && globalThis.FaceDetector;

FaceDetectorInit.propTypes = {
successCb: PropTypes.func,
// successCb: PropTypes.func,
failureCb: PropTypes.func,
loadingCb: PropTypes.func,
successMsg: PropTypes.string,
// successMsg: PropTypes.string,
failureMsg: PropTypes.object,
zIndex: PropTypes.number,
cameraType: PropTypes.oneOf(['back', 'front']),
};

FaceDetectorInit.defaultProps = {
successCb: () => {},
// successCb: () => {},
failureCb: () => {},
loadingCb: () => {},
successMsg: '',
// successMsg: '',
failureMsg: { ...failureMsgDefault },
zIndex: 9,
cameraType: 'back',
Expand Down
27 changes: 15 additions & 12 deletions __app/component/LiveLocationTracking/LiveLocationTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import dependentJsService from '../services/dependentJsService';
import { handleError, handleSuccess, handleLoading } from '../services/handlerService';
import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'LiveLocationTracking is not supporting in your device',
permissionDenied: 'Permission Denied',
unableToLocateDirection: 'Unable To get Updated Location',
browserPermissionAPIFailed: 'Unable to check browser permission',
unableToLoadGoogleAPI: 'Unable to load google api script',
locationNotFound: 'Unable To get Updated Location',
googleAPIKeyMissing: 'Unable to check browser permission',
error: '',
};

const checkPermitByBrowser = async (failureMsg, failureCb) => {
try {
const permissions = await navigator.permissions.query({ name: 'geolocation' });
Expand Down Expand Up @@ -35,7 +46,7 @@ function LiveLocationTracking({
successCb,
failureCb,
successMsg,
failureMsg,
failureMsg: failureMsgProps,
loadingCb,
googleKey,
isProdKey,
Expand All @@ -53,6 +64,7 @@ function LiveLocationTracking({
let directionsService;
let directionsRenderer;
let watchID = null;
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };

const createMarker = async (googleMap, userCurrenrLocation, url) => {
const { AdvancedMarkerElement } = await google.maps.importLibrary('marker');
Expand Down Expand Up @@ -238,17 +250,8 @@ LiveLocationTracking.defaultProps = {
failureCb: () => {},
loadingCb: () => {},
successMsg: '',
failureMsg: {
unSupported: 'LiveLocationTracking is not supporting in your device',
permissionDenied: 'Permission Denied',
unableToLocateDirection: 'Unable To get Updated Location',
browserPermissionAPIFailed: 'Unable to check browser permission',
unableToLoadGoogleAPI: 'Unable to load google api script',
locationNotFound: 'Unable To get Updated Location',
// invalidLatLng: '',
googleAPIKeyMissing: 'Unable to check browser permission',
error: '',
},
failureMsg: { ...failureMsgDefault },

destinationLatLng: { lat: 12.9387901, lng: 77.6407703 },
isProdKey: true,
googleKey: '',
Expand Down
25 changes: 14 additions & 11 deletions __app/component/LocateMe/LocateMe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import Wrapper from '../Wrapper/Wrapper';
import { handleSuccess, handleError, handleLoading } from '../services/handlerService';
import dependentJsService from '../services/dependentJsService';

const failureMsgDefault = {
unSupported: 'LocationMe is not supporting in your device',
permissionDenied: 'Permission Denied',
googleAPIKeyMissing: 'Google Key is missing',
unableToLoadGoogleAPI: 'Unable to load google api script',
browserPermissionAPIFailed: 'Unable to check browser permission',
invalidLatLng: 'Invalid Lat lng',
error: '',
};

const checkPermitByBrowser = async (failureMsg, failureCb) => {
try {
const permissions = await navigator.permissions.query({ name: 'geolocation' });
Expand Down Expand Up @@ -79,18 +89,19 @@ function LocateMe({
successCb,
failureCb,
successMsg,
failureMsg,
failureMsg: failureMsgProps,
loadingCb,
children,
isProdKey,
googleKey,
}) {
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };

const onClick = async () => {
if (LocateMe.isBrowserSupport()) {
handleLoading({ loadingCb });
const isPermitByBrowser = await checkPermitByBrowser(failureMsg, failureCb);
const isScriptInBrowser = await checkScriptInBrowser(

failureMsg,
failureCb,
isProdKey,
Expand Down Expand Up @@ -154,15 +165,7 @@ LocateMe.defaultProps = {
failureCb: () => {},
loadingCb: () => {},
successMsg: 'Located Successfully',
failureMsg: {
unSupported: 'LocationMe is not supporting in your device',
permissionDenied: 'Permission Denied',
browserPermissionAPIFailed: 'Unable to check browser permission',
googleAPIKeyMissing: 'Google Key is missing',
unableToLoadGoogleAPI: 'Unable to load google api script',
invalidLatLng: 'Invalid Lat lng',
error: '',
},
failureMsg: { ...failureMsgDefault },
isProdKey: true,
googleKey: '',
};
Expand Down
16 changes: 10 additions & 6 deletions __app/component/PhoneBook/PhoneBook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ import PropTypes from 'prop-types';
import { handleSuccess, handleError, handleLoading } from '../services/handlerService';
import Wrapper from '../Wrapper/Wrapper';

const failureMsgDefault = {
unSupported: 'PhoneBook is not supporting in your device',
cancelled: 'Feature Cancelled',
error: 'Unable to fetch details from PhoneBook',
};

function PhoneBook({
successCb,
failureCb,
loadingCb,
successMsg,
failureMsg,
failureMsg: failureMsgProps,
children,
contactProperty,
isSelectMultiple,
}) {
const failureMsg = { ...failureMsgDefault, ...failureMsgProps };

const getContacts = async () => {
const opts = { multiple: isSelectMultiple };
if (PhoneBook.isBrowserSupport()) {
Expand Down Expand Up @@ -60,11 +68,7 @@ PhoneBook.defaultProps = {
failureCb: () => {},
loadingCb: () => {},
successMsg: 'Phonebook details fetch Successfully',
failureMsg: {
unSupported: 'PhoneBook is not supporting in your device',
cancelled: 'Feature Cancelled',
error: 'Unable to fetch details from PhoneBook',
},
failureMsg: { ...failureMsgDefault },
contactProperty: ['name', 'email', 'tel', 'address', 'icon'],
isSelectMultiple: false,
};
Expand Down
Loading

0 comments on commit d64ab7b

Please sign in to comment.