1.0.86 • Published 1 year ago

community-widget-test v1.0.86

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

About

This package was created to implement a chat between mentors and explorers on the prodigyfinance.com.

Before installation

  • ensure that you have get-stream API key which can be found on get-stream's dashboard
  • you have access to the current user's userAccessToken needed for logging in.

Steps to install the package

  1. add .npmrc file to the root of your project with following contents:
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}
@prodigyfinance:registry=https://npm.pkg.github.com
  1. run
npm i @prodigyfinance/community-widget
  1. create .env variable containing get-stream API key (e.g. GATSBY_GETSTREAM_API_KEY)
  2. create a component containing community-widget and pass needed props:
  • streamApiKey - get-stream API key (e.g. process.env.GATSBY_GETSTREAM_API_KEY)
  • navigationState - an object { isChannelsListScreen: boolean, selectedMentorId: string } that contains info needed for redirecting the user inside of the widget after the user is redirected back to the website after successfull logging in. For example, if navigationState.isChannelsListScreen === true, user gets instantly redirected to the screen with a list of their active channels. Or if navigationState.selectedMentorId contains an id of the mentor, the user gets redirected to chat-screen with that particulat mentor. These values can be obtained through params and passed to the widget when the user gets back to the web-site after successfull loging in
  • onLoginButtonClick and onSignUpButtonClick - callbacks that get invoked when the user presses 'Log in' or 'Sign Up' buttons on widget. Their only argument is an object which contains { isChannelsListScreen: boolean } or { selectedMentorId: string }. The argument is suposed to be passed to login-api/signup-api through params and the user is supposed to be redirected to login/sign-up page. The query may look like https://www.loginapi.com/login?isChannelsListScreen=true or https://www.loginapi.com/login?selectedMentorId=someCrazyHashedMentorId. E.g. possible scenarios: - unauthenticated user presses a button that leads to the screen with active channels user sees a screen with 'Log In' button user presses 'Log In' button (that's the point where { isChannelsListScreen: true } is passed to login site through params) user gets redirected to login-site, fills the creadentials and is successfully logged in user gets redirected back to the website ({ isChannelsListScreen: true } is passed through the params to website) user sees the widget with channels-list screen - unauthenticated user presses a button to chat with some mentor user sees a screen with 'Log In' button user presses 'Log In' button (that's the point where { selectedMentorId: 'someCrazyHashedMentorId } is passed to login site through params) user gets redirected to login-site, fills the creadentials and is successfully logged in user gets redirected back to the website ({ selectedMentorId: 'someCrazyHashedMentorId } is passed through the params to website) user sees the widget with chat screen with mentor who's id is someCrazyHashedMentorId.
  • isAuthStateLoading - to prevent the widget from displaying while authentication process is in progress
  • userAccessToken - access token needed for authenticating the user on community-backend
  • launchDarklyApiKey - api key for launch-darkly
  • baseUrl - url to the backend
import { CommunityWidget } from '@prodigyfinance/community-widget'

const CommunityWidgetContainer = () => {
  const { userAccessToken, isAuthStateLoading } = useAuthContext();
  const { widgetNavigationState } = useAppContext()

  const onLoginCallback = (navigationValue) => {
    dispatch({
      type: 'UPDATE_WIDGET_NAVIGATION_STATE',
      payload: navigationState,
    })
  }

  return (
    <CommunityWidget
      isAuthStateLoading={isAuthStateLoading}
      streamApiKey={process.env.GATSBY_GETSTREAM_API_KEY}
      onLoginButtonClick={onLoginCallback}
      onSignUpButtonClick={onSignUpButtonClick}
      navigationState={widgetNavigationState}
      userAccessToken={user?.access_token}
      launchDarklyApiKey={process.env.GATSBY_PRODIGY_LAUNCH_DARKLY_CLIENT_ID}
      baseUrl={process.env.REACT_APP_BACKEND_URL}
    />
  );
};
  1. put it into your website, e.g. into gatsby-browser.js:
export const wrapRootElement = ({ element }) => {
  return (
    <ErrorBoundary>
      <GlobalContextProvider>
        <CommunityWidgetContainer />
        {element}
      </GlobalContextProvider>
    </ErrorBoundary>
  );
};

Happy hacking!

1.0.69

2 years ago

1.0.68

2 years ago

1.0.67

2 years ago

1.0.73

2 years ago

1.0.72

2 years ago

1.0.71

2 years ago

1.0.70

2 years ago

1.0.77

2 years ago

1.0.76

2 years ago

1.0.75

2 years ago

1.0.74

2 years ago

1.0.79

1 year ago

1.0.78

2 years ago

1.0.80

1 year ago

1.0.84

1 year ago

1.0.83

1 year ago

1.0.82

1 year ago

1.0.81

1 year ago

1.0.86

1 year ago

1.0.85

1 year ago

1.0.62

2 years ago

1.0.61

2 years ago

1.0.60

2 years ago

1.0.66

2 years ago

1.0.65

2 years ago

1.0.64

2 years ago

1.0.63

2 years ago

1.0.48

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.49

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.55

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.59

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.39

2 years ago

1.0.17

2 years ago

1.0.38

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.40

2 years ago

1.0.44

2 years ago

1.0.22

2 years ago

1.0.43

2 years ago

1.0.21

2 years ago

1.0.42

2 years ago

1.0.20

2 years ago

1.0.41

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.33

2 years ago

1.0.11

2 years ago

1.0.32

2 years ago

1.0.10

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.37

2 years ago

1.0.15

2 years ago

1.0.36

2 years ago

1.0.14

2 years ago

1.0.35

2 years ago

1.0.13

2 years ago

1.0.34

2 years ago

1.0.12

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago