Skip to content

Contains core functionality for building React and React-Native applications

License

Notifications You must be signed in to change notification settings

samanthamcq/apax-react-core

 
 

Repository files navigation

apax-react-core

Build Status

Contains core react functionality developed by Apax Software LLC

Available functionality includes handling user account signup and login to DRF backends.

Usage

Connecting Locally

To connect to this repository locally, go to the root directory for apax-react-core:

yarn link

Then go to the project you want to connect (at the root level) and enter:

yarn link apax-react-core

To separate the projects again:

yarn unlink

inside apax-react-core level terminal.

Initialize Environment

This library requires a bit of configuration before it can be used. To do this, dispatch the following action early on in your application startup:

setEnv({app_evironment})

Example:

./redux/sagas.js

import { put } from 'react-saga/effects';
import { setEnv } from 'apax-react-core';

function* rootSaga () {
  ...

  yield put(setEnv({
    api_domain: process.env.REACT_APP_API_DOMAIN,
    api_root: process.env.REACT_APP_API_ROOT,
    token_name: process.env.REACT_APP_TOKEN_NAME,
  }));

  ...
}

./redux/index.js

...
import { envReducer as env } from 'apax-react-core';

...

export const rootReducer = combineReducers({
  env,
  ...
})

Environment Options

{
  // Domain name of backing server
  api_domain: 'localhost:8000',

  // Root URL of the api (do not include the '/api')
  api_root: 'http://localhost:8000',

  // Name to give the cookie when storing the user token
  token_name: 'react_core_app'
}

User Account

This library provides signup and login functionality for DRF backends. To use this functionality add the account sagas and reducers to you application:

./redux/index.js

import { accountReducer as account } from 'apax-react-core';

export const rootReducer = combineReducer({
  account,
  ...
});


./redux/sagas.js

import { accountSagas } from 'apax-react-core';

function* rootSaga () {
  ...
  yield call(accountSagas);
}

export default rootSaga;

Signup User

./pages/auth/Signup.js

import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { signup } from 'apax-react-core';

...

export default function Signup() {
  const history = useHistory();
  const dispatch = useDispatch();

  ...

  const onFormSubmit = (formData) => {
    dispatch(signup(formData, history));
  }
  ...
}

Login User

./pages/auth/Login.js

import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { login } from 'apax-react-core';

...

export default function Signup() {
  const history = useHistory();
  const dispatch = useDispatch();

  ...

  const onFormSubmit = (creds) => {
    dispatch(login(creds, history));
  }
  ...
}

API

The following API methods are available:

apiGet(path, data, authenticationRequired = true)

apiPost(path, data, authenticationRequired = true)

apiPut(path, data, authenticationRequired = true)

apiPatch(path, data, authenticationRequired = true)

apiDelete(path, authenticationRequired = true)

Usage

import {
  apiGet
} from 'apax-react-core';


...

const response = yield apiGet('api/mypath/');

License

MIT License

Copyright (c) 2020 Apax Software LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Contains core functionality for building React and React-Native applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 97.8%
  • HTML 1.5%
  • CSS 0.7%