{"id":20832495,"url":"https://github.com/codetanzania/ewea-api-states","last_synced_at":"2025-05-08T01:26:01.083Z","repository":{"id":35130681,"uuid":"210335963","full_name":"CodeTanzania/ewea-api-states","owner":"CodeTanzania","description":"EWEA Redux state management library","archived":false,"fork":false,"pushed_at":"2025-04-03T22:42:08.000Z","size":2844,"stargazers_count":7,"open_issues_count":15,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-30T12:16:46.957Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeTanzania.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":"GOVERNANCE.md","roadmap":null,"authors":null,"dei":null}},"created_at":"2019-09-23T11:17:36.000Z","updated_at":"2021-06-05T16:03:11.000Z","dependencies_parsed_at":"2024-01-25T13:27:05.047Z","dependency_job_id":"0e877652-558a-4d14-86ae-94823ec4b728","html_url":"https://github.com/CodeTanzania/ewea-api-states","commit_stats":{"total_commits":915,"total_committers":4,"mean_commits":228.75,"dds":"0.23387978142076504","last_synced_commit":"adcedca422dee822b1203e48fa45b8d16da91f39"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeTanzania%2Fewea-api-states","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeTanzania%2Fewea-api-states/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeTanzania%2Fewea-api-states/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeTanzania%2Fewea-api-states/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeTanzania","download_url":"https://codeload.github.com/CodeTanzania/ewea-api-states/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252980340,"owners_count":21835215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T00:12:02.570Z","updated_at":"2025-05-08T01:26:01.062Z","avatar_url":"https://github.com/CodeTanzania.png","language":"JavaScript","readme":"# EWEA API States\n\n[![Build Status](https://travis-ci.com/CodeTanzania/ewea-api-states.svg?branch=develop)](https://travis-ci.org/CodeTanzania/ewea-api-states)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)\n\nSimplify API calls and state management on top of redux and others.\n\n## Installation\n\nUsing npm\n\n```sh\nnpm install @codetanzania/ewea-api-states\n```\n\nUsing yarn\n\n```sh\nyarn add @codetanzania/ewea-api-states\n```\n\n## Usage\n\nAll actions exposed by `ewea-api-states` are wrapped with dispatch function, so the is no need to dispatch them again just invoke them.\n\nThe following is the list of all resources exposed by this library.\n\n- AdministrativeArea\n- agency\n- event\n- eventAction\n- eventFunction\n- eventGroup\n- eventType\n- feature\n- focalPerson\n- notificationTemplate\n- partyRole\n\n  For each resource you can get it's exposed actions as follows;\n\n  \u003e Replace events with the name of the module you want\n\n```js\nimport { reduxActions } from '@codetanzania/ewea-api-states';\nconst {\n  clearEventFilters,\n  clearEventsSort,\n  closeEventForm,\n  deleteEvent,\n  filterEvents,\n  getEvents,\n  getEvent,\n  selectEvent,\n  openEventForm,\n  paginateEvents,\n  postEvent,\n  putEvent,\n  refreshEvents,\n  searchEvents,\n  sortEvents,\n  loadMoreEvents,\n  eventsReport,\n} = reduxActions;\n```\n\n### Store Structure\n\nThe structure of the store for each resource is\n\n```js\nconst store = {\n events: {\n    list: [],\n    selected: null,\n    page: 1,\n    total: 0,\n    size: 0,\n    pages: 1,\n    loading: false,\n    posting: false,\n    showForm: false,\n    schema: null,\n    filter: null,\n    sort: null,\n    hasMore:false,\n    q: undefined\n  },\n  ...\n};\n```\n\n### StoreProvider\n\nThis is a wrapper around react-redux `Provider` component. You can use it as follows\n\n```jsx\nimport { render } from 'react-dom';\nimport { StoreProvider } from '@codetanzania/ewea-api-states';\n\n// store provider\nrender(\n  \u003cStoreProvider\u003e\n    \u003cApp /\u003e\n  \u003c/StoreProvider\u003e,\n  document.getElementById('root')\n);\n```\n\n### Connect\n\nThis is a wrapper around react-redux `connect` HOC with little improvement over it. You can use it as follows\n\n```js\nimport { Connect } from '@codetanzania/ewea-api-states';\n\n// for component\nfunction EventList({ events }){\n  return(\n    // jsx stuff\n  );\n}\n\n// connect EventList component to store\nexport Connect(EventList, {\n    events: 'events.list'\n});\n\n```\n\n### How to use exposed actions\n\nSome of these actions accepts two callback functions which will be executed on Success and Error scenarios as shown below;\n\n#### Fetch Data\n\n```js\nconst { getEvents, getEvent } = reduxActions;\n\ngetEvents();\n\ngetEvents(eventId);\n```\n\n#### Create Data\n\n```js\nconst { postEvent } = reduxActions;\n\npostEvent(event, onSuccess, onError);\n```\n\n\u003e If you want to keep filters upon successful update action\n\n```js\npostEvent(event, onSuccess, onError, { filters: {} });\n```\n\n#### Update Data\n\n```js\nconst { putEvent } = reduxActions;\n\nputEvent(event, onSuccess, onError);\n```\n\n#### Archive/Delete Data\n\n```js\nconst { deleteEvent } = reduxActions;\n\ndeleteEvent(eventId, onSuccess, onError);\n```\n\n#### Searching\n\n```js\nconst { searchEvents } = reduxActions;\n\nsearchEvents(searchQueryString);\n```\n\n#### Filtering\n\n```js\nconst { filterEvents, clearEventFilters } = reduxActions;\n\nfilterEvents({ eventType: eventTypeId }, onSuccess, onError);\n\n// clearing filters\nclearEventFilters(onSuccess, onError);\n\n//  keep some filters from being cleared. This won't reset plan field in filter object\nclearEventFilters(onSuccess, onError, ['eventType']);\n```\n\n#### Pagination\n\n```js\nconst { paginateEvents } = reduxActions;\n\npaginateEvents(pageNumber);\n```\n\n#### Sorting\n\n```js\nconst { sortEvents, clearEventsSort } = reduxActions;\n\nsortEvents({ name: 1 }, onSuccess, onError);\n\n// clear sort\n\nclearEventsSort(onSuccess, onError);\n```\n\n### Infinity Scroll\n\n```js\nconst { loadMoreEvents } = reduxActions;\n\nloadMoreEvents();\n```\n\n### Get Report\n\n```js\nconst { getEventsReport } = reduxActions;\n\ngetEventsReport();\n```\n\n\u003e Note: This library depends on [ewea-api-client](https://github.com/CodeTanzania/ewea-api-client) to work, so in order to specify API URL add `.env` file on your project root folder and specify your API URL under `REACT_APP_EWEA_API_URL=[specify API BASE URL here]`\n\n### LICENSE\n\nMIT License\n\nCopyright (c) 2019 - present Code Tanzania \u0026 Contributors\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodetanzania%2Fewea-api-states","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodetanzania%2Fewea-api-states","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodetanzania%2Fewea-api-states/lists"}