Quiz component

Components Visuals

To unlock early access to the component Get Access

Installation

To install the Quest react-native-sdk into your project, follow these steps:

  • Open your terminal/command prompt.

  • Navigate to your project's root directory using the cd command if you're not already there.

  • Run the following command to install the quest-sdk package using npm:

npm install @questlabs/react-native-sdk

This command will download and install the package and its dependencies into your project.

Make sure your project has npm and Node.js installed, and that you have the necessary permissions to install packages in your project directory.

Usage

Root Component

  • Import the QuestProvider Component: Import the QuestProvider component from the @questlabs/react-sdk package.

import { QuestProvider } from '@questlabs/react-sdk';
  • Pass the Required Props: Pass the required props to the QuestProvider. The required props are apiKey, apiSecret, entityId and authenticationToken.

Component Usage

To integrate the useGamifiedQuiz component into your React native application, follow these steps.

  • Import useGamifiedQuiz Hook: Import the useGamifiedQuiz component from the @questlabs/react-sdk package.

  • Import the Gamified Component: Import the Gamified component from the @questlabs/react-sdk package.

  • Pass the Required Props: Pass the required props to the useGamifiedQuiz . The required props are questId, questUserId, and questToken or if user don't have quest User id then they can pass own userId to get questUserId and Token.

import { useGamifiedQuiz , Gamified } from "@questlabs/react-native-sdk";

Don't not use QuestProvider and useGamifiedQuiz Hook in same file

Props of Gamified Component

The Gamified component accepts the following props

Props NameTypeRequire Details

actions

ICriteria[]

Require

in offline user need to provide the require filed data.

questId

string

Optional

Provied questId

questUserId

string

Optional

Provied the userId

userToken

string

Optional

Provied Quest Token

loading

boolean

Optional

don't use in offline mode.

onUpdateAction

(actionID: string, answer: (string | number)[])

Optional

Create your oen function for updateing the action.

header

string

Optional

Component header text

campaignVariationId

string

Optional

Id For verification.

onError

Function

Optional

For Showing the Error.

styleConfig

Object

Optional

An object containing Styling properties for styling various components within the get started process, including form, topbar, headings, descriptions, and buttons.

Style Props

styleConfig {
  Form?: ViewStyle;
  Heading?: TextStyle;
  Input?: ViewStyle;
  PrimaryButton?: ViewStyle | TextStyle;
  SecondaryButton?: ViewStyle | TextStyle;
  Footer?: {
    FooterStyle?: ViewStyle;
    FooterText?: TextStyle;
    FooterIcon?: TextStyle;
  };
  MultiChoice?: {
    style?: TextStyle ,
    selectedStyle?: ViewStyle
 },
  FormContainer?: ViewStyle;
  Question?: TextStyle;
  ThanksPopup?: ViewStyle;
  ThanksPopupHeading?: TextStyle;
  ThanksPopupDescription?: TextStyle;
  thanksPopUpFooter?: {
    thanksPopUpFooterStyle?: ViewStyle;
    thanksPopUpFooterText?: TextStyle;
    thanksPopUpFooterIcon?: TextStyle;
  };
  ThanksPopupGotoHome?: ViewStyle | TextStyle;
}

Example Usage

App.js

import { SafeAreaView, StyleSheet, StatusBar } from "react-native";
import React, { useState } from "react";
import { QuestProvider } from "@questlabs/react-native-sdk";
import DemoComponent from "./DemoComponent";

export default function App() {
return (
    <SafeAreaView style={styles.container}>
      <StatusBar />
      <QuestProvider
        apiKey="Your-Api-Key"
        apiSecret="Your-Api-Secret"
        entityId="Your-Api-entityId"
        authenticationToken="Your-authentication-token"  >
        
        <DemoComponent />
        
        </QuestProvider>
   
    </SafeAreaView>
  );
}

DemoComponent.tsx

import React from "react";
import {Gamified,useGamifiedQuiz} from "@questlabs/react-native-sdk";
const DemoComponent = () => {
  // const gamified= useGamifiedQuiz({
  //   questId: "Your-Quest_ID" ,
  //   userId:"5235trfet365try67ywry5"
  //   })

  const gamified= useGamifiedQuiz({
    questId: "Your-Quest_ID" ,
    questUserId: "Your-user-id",
    questToken: "Your-Token-id" 
    });
  return (
    <>
    <Gamified
        actions={gamified.actions}
        loading={gamified.loading}
        campaignVariationId={gamified.campaignVariationId}
        questId={gamified.questId}
        questToken={gamified.userToken}
        questUserId={gamified.questUserId}
        // styleConfig={
        //   {
        //     Heading:{color:"yellow"},
        //     Footer:{
        //       FooterIcon:{
        //         color:'yellow'
        //       },
        //       FooterStyle:{backgroundColor:"red"},
        //       FooterText:{color:'yellow'}
        //     },
        //     FormContainer:{backgroundColor:'gray'},
        //     Input:{backgroundColor:"red"},
        //     PrimaryButton:{backgroundColor:"red",color:"yellow"},
        //     SecondaryButton:{backgroundColor:"blue",color:"white"},
        //     Question:{color:'yellow'},
        //     ThanksPopup:{backgroundColor:"red"},
        //     ThanksPopupDescription:{color:"red"},
        //     ThanksPopupHeading:{color:'red'},
        //     ThanksPopupGotoHome:{backgroundColor:"red",color:"white"},
        //     thanksPopUpFooter: {
        //       thanksPopUpFooterText: {
        //         color: "red"
        //       },
        //       thanksPopUpFooterIcon: {
        //         color: "red"
        //       },
        //       thanksPopUpFooterStyle: {
        //         backgroundColor: "yellow"
        //       }
        //     }
        //   }
        // }

        // actions={[
        //   {
        //     actionId: "123",
        //     actionType: "USER_INPUT_TEXT",
        //     answer: [],
        //     title: "first"

        //   },
        //   {
        //     actionId: "32",
        //     actionType: "USER_INPUT_TEXT",
        //     answer: [],
        //     title: "2"

        //   },
        //   {
        //     actionId: "342",
        //     actionType: "USER_INPUT_SINGLE_CHOICE",
        //     answer: [],
        //     options: [1, 2, 3, 4, 5],
        //     title: "3"

        //   },
        //   {
        //     actionId: "123",
        //     actionType: "USER_INPUT_MULTI_CHOICE",
        //     answer: [],
        //     options: ['df5', 'afg', 'sdgfh', 'asdg'],
        //     title: "4"

        //   },
        //   {
        //     actionId: "5673563",
        //     actionType: "USER_INPUT_TEXT",
        //     answer: [],
        //     title: "5"

        //   },

        // ]}
      />
    </>
  );
};
export default DemoComponent;

Demo

Last updated