Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Refactor duplicated logic to grab active hotlines #432

Open
deepanchal opened this issue Sep 6, 2023 · 0 comments
Open

UI: Refactor duplicated logic to grab active hotlines #432

deepanchal opened this issue Sep 6, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@deepanchal
Copy link
Contributor

Description

Replace this logic with reusable hook/util in the repo:

const ccuApi = useApi();
const fieldsToFetch = [
  'id',
  'name',
  'short_name',
  'active_phone_number',
  'start_at',
];
const { isDataLoading, data } = ccuApi(
  '/incidents?fields=id,name,short_name,active_phone_number&limit=200&sort=-start_at',
  {
    method: 'GET',
    params: {
      fields: fieldsToFetch.join(','),
      limit: 200,
      sort: '-start_at',
    },
  },
);
const incidentList = computed(() => data.value?.results);
function getIncidentPhoneNumbers(incident) {
  if (Array.isArray(incident.active_phone_number)) {
    return incident.active_phone_number
      .map((number) => formatNationalNumber(String(number)))
      .join(', ');
  }
  return formatNationalNumber(String(incident.active_phone_number));
}
function filterNumbers(item) {
  return item.filter((filterItem) => filterItem.active_phone_number);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant