# sherl-react-sdk

> Package aims to provide basic utilities to interact with sherl backend

[![NPM](https://img.shields.io/npm/v/sherl-react-sdk.svg)](https://www.npmjs.com/package/sherl-react-sdk) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

Check other traductions : [French](./README.fr.md)

## Installation

Clone the library into the same directory where is the project :

```bash
git clone git@git.winzana.com:sherl/sherl-react-sdk.git
```

In the project where you want to use the module :

```bash
yarn add link:../sherl-react-sdk
```

Check if dependencies below are already installed :

```bash
yarn add axios i18next react react-i18next react-redux redux
```

Configure axios :

```ts
axios.defaults.baseURL = <baseURL>
```

```ts
import { initialize } from 'sherl-react-sdk';

initialize(
  <apiKey>,
  <apiSecret>,
  <instanceName>, // Will produce https://api.sherl.io
  `<baseURL>`,// Optiona
  `<analytics_url>`, // Optional
  `<cms_url>`, // Optional
  `<place_url>`, // Optional
  `<calendar_url>`, // Optional
  `<communication_url>`, // Optional
  `<opinion_url>`, // Optional
  `<pdf-url>`, // Optional
);
```

```tsx
import { store } from 'sherl-react-sdk';
import { Provider } from 'react-redux';

export const App = () => <Provider store={store}>...app</Provider>;
```

Start the packager :

```bash
cd sherl-react-sdk && yarn start
```

## Usage

The package is decoupled by domains. For example if you need to work with the organization domain you should use it like this :

```jsx
import { Organization } from 'sherl-react-sdk';

type OrganizationMetadatas = {
    constraints: string;
};

const MyComponent = () => {

    const { getOrganization, organization, loading, error } = Organization.useOrganizations<OrganizationMetadatas>();

    return ...;
};

```

## Troobleshooting

`Cannot read property 'referencesPath' of undefined:`

Turn this :

```ts
try {
  response = await PersonApi.getPersons(page, itemsPerPage, params);
} catch ({ name, response: responseError, isAxiosError, stack, ...rest }) {}
```

Into this :

```ts
try {
  response = await PersonApi.getPersons(page, itemsPerPage, params);
} catch (err) {
  const { name, response: responseError, isAxiosError, stack, ...rest } = err;
}
```

You have to specify types for which one has metadatas.

## Domains Available

- Auth
- Analytics
- BugReport
- Calendar
- Claim
- CMS
- Communication
- Config
- Contact
- Gallery
- Media
- Notification
- Opinion
- Order
- Organization
- Pdf
- Person
- Place
- Shop
- Subscription
- User

More docs to come in a future...

## License

MIT © [support@winzana.com](https://github.com/support@winzana.com)
