Skip to content

Commit

Permalink
Use constants to avoid magic values
Browse files Browse the repository at this point in the history
  • Loading branch information
RodriSanchez1 committed May 20, 2024
1 parent ed80599 commit a9cd40c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/components/Communicator/Communicator.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
GET_API_MY_COMMUNICATORS_FAILURE,
GET_API_MY_COMMUNICATORS_STARTED
} from './Communicator.constants';

import { defaultCommunicatorID } from './Communicator.reducer';
import API from '../../api';

export function importCommunicator(communicator) {
Expand Down Expand Up @@ -55,11 +55,13 @@ export function upsertApiCommunicator(communicator) {
const {
communicator: { communicators }
} = getState();
const SHORT_ID_MAX_LENGTH = 14;

// If the communicator is not on the local state return
if (!communicators.find(c => c.id === communicator.id)) return;

communicator.id.length < 14 || communicator.id === 'cboard_default'
communicator.id.length < SHORT_ID_MAX_LENGTH ||
communicator.id === defaultCommunicatorID
? dispatch(createApiCommunicator(communicator, communicator.id)).catch(
error => {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Communicator/Communicator.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from './Communicator.constants';
import { LOGIN_SUCCESS, LOGOUT } from '../Account/Login/Login.constants';

const defaultCommunicatorID = 'cboard_default';
export const defaultCommunicatorID = 'cboard_default';
const initialState = {
communicators: defaultCommunicators,
activeCommunicatorId: defaultCommunicatorID
Expand Down

0 comments on commit a9cd40c

Please sign in to comment.