Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates react to 18.2.0 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Netacci
Copy link

@Netacci Netacci commented Oct 10, 2023

Updates react dependency to 18.2.0 as dojah is compatible to only 16.0.0

@OkoloJohnbosco
Copy link

@Netacci u can just create your custom Dojah component, you can copy the code below create a file and paste it within, then import Dojah from the file and use the same way as tou would use the one from "react-dojah"

`import React from "react";

export type ResType = "success" | "error" | "close" | "start" | "loading";
export type UserType =
| "first_name"
| "last_name"
| "dob"
| "residence_country"
| "email";
export type GovtType = "bvn" | "nin" | "mobile";
interface DojahResponse {
response: (type: ResType, res?: any) => void;
appID: string;
publicKey: string;
type:
| "custom"
| "verification"
| "identification"
| "verification"
| "liveness";
config?: Record<string, unknown>;
userData?: Partial<Record<UserType, string>>;
metadata: Record<string, unknown>;
govData?: Partial<Record<GovtType, unknown>>;
}

declare global {
interface Window {
Connect: (options: Record<string, unknown>) => void;
dojah: any;
}
}

function Dojah(props: DojahResponse) {
let script: HTMLScriptElement;

React.useEffect(() => {
start();
return () => stop();
}, []);

const load = () => {
const { response } = props;
response("start");
open();
};

const error = () => {
const { response } = props;
response("error");
//document.head.removeChild(script)
};

const start = () => {
const { response } = props;
let { uri } = Dojah.config;
if (window.dojah && window.dojah.uri) {
uri = window.dojah.uri;
}
response("loading");
script = document.createElement("script");
script.addEventListener("load", load);
script.addEventListener("complete", load);
script.addEventListener("error", error);
script.src = uri;
script.async = true;
document.head.appendChild(script);
};

const stop = () => {
script.removeEventListener("load", load);
script.removeEventListener("error", error);
//document.head.removeChild(script)
};

const open = () => {
const {
appID,
publicKey,
type,
response,
config,
metadata,
userData,
govData,
} = props;

const options = {
  app_id: appID,
  p_key: publicKey,
  type,
  config,
  metadata,
  user_data: userData,
  gov_data: govData,
  _getLocation: function () {
    return new Promise(function (resolve) {
      navigator.geolocation.getCurrentPosition(function (location) {
        resolve({
          latitude: location.coords.latitude,
          longitude: location.coords.longitude,
          accuracy: location.coords.accuracy,
        });
      });
    });
  },
  onSuccess: (data: Record<string, unknown>) => {
    response("success", data);
  },
  onError: (err: Error) => {
    response("error", err);
    script.remove();
  },
  onClose: (err: Error) => {
    response("close", err);
    script.remove();
  },
};
const connect = new (window.Connect as any)(options);
connect.setup();
connect.open();

};
return <></>;
}

Dojah.config = {
uri: "https://widget.dojah.io/widget.js",
};

export default Dojah;
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants