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

[INV-3528] actionCreators #3648

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/src/UI/OfflineDataSync/OfflineDataSyncTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { Button, LinearProgress } from '@mui/material';
import { OfflineActivityRecord, selectOfflineActivity } from 'state/reducers/offlineActivity';
import { useSelector } from 'utils/use_selector';
import { useDispatch } from 'react-redux';
import { ACTIVITY_GET_LOCAL_REQUEST, ACTIVITY_OFFLINE_DELETE_ITEM, ACTIVITY_RUN_OFFLINE_SYNC } from 'state/actions';
import { ACTIVITY_OFFLINE_DELETE_ITEM, ACTIVITY_RUN_OFFLINE_SYNC } from 'state/actions';
import Delete from '@mui/icons-material/Delete';
import './OfflineDataSync.css';
import moment from 'moment';
import { FileOpen } from '@mui/icons-material';
import { ActivitySubtypeShortLabels } from 'sharedAPI';
import { useHistory } from 'react-router-dom';
import Activity from 'state/actions/activity/Activity';

export const OfflineDataSyncTable = () => {
const { working, serializedActivities } = useSelector(selectOfflineActivity);
Expand Down Expand Up @@ -60,7 +61,7 @@ export const OfflineDataSyncTable = () => {
<Button
disabled={!(workingOffline || authenticated)}
onClick={() => {
dispatch({ type: ACTIVITY_GET_LOCAL_REQUEST, payload: { activityID: key } });
dispatch(Activity.getLocal(key));
history.push(`/Records/Activity:${key}/form`);
}}
>
Expand Down
20 changes: 7 additions & 13 deletions app/src/UI/Overlay/FormMenuButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ import { Button } from '@mui/material';
import { useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import { useSelector } from 'utils/use_selector';
import {
ACTIVITY_COPY_REQUEST,
ACTIVITY_DELETE_REQUEST,
ACTIVITY_PASTE_REQUEST,
ACTIVITY_SAVE_REQUEST,
ACTIVITY_SUBMIT_REQUEST,
OVERLAY_MENU_TOGGLE
} from 'state/actions';
import { OVERLAY_MENU_TOGGLE } from 'state/actions';
import Activity from 'state/actions/activity/Activity';

export const FormMenuButtons = (props) => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -39,23 +33,23 @@ export const FormMenuButtons = (props) => {
}, [accessRoles, username, activityCreatedBy]);

const handleSaveDraft = () => {
dispatch({ type: ACTIVITY_SAVE_REQUEST });
dispatch(Activity.save());
dispatch({ type: OVERLAY_MENU_TOGGLE });
};
const handlePublish = () => {
dispatch({ type: ACTIVITY_SUBMIT_REQUEST });
dispatch(Activity.submit());
dispatch({ type: OVERLAY_MENU_TOGGLE });
};
const handleCopy = () => {
dispatch({ type: ACTIVITY_COPY_REQUEST });
dispatch(Activity.copy());
dispatch({ type: OVERLAY_MENU_TOGGLE });
};
const handlePaste = () => {
dispatch({ type: ACTIVITY_PASTE_REQUEST });
dispatch(Activity.paste());
dispatch({ type: OVERLAY_MENU_TOGGLE });
};
const handleDelete = () => {
dispatch({ type: ACTIVITY_DELETE_REQUEST });
dispatch(Activity.deleteReq());
dispatch({ type: OVERLAY_MENU_TOGGLE });
setTimeout(() => history.back(), 5000);
};
Expand Down
10 changes: 5 additions & 5 deletions app/src/UI/Overlay/Records/NewRecordDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { useHistory } from 'react-router-dom';
import { useEffect, useState } from 'react';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import { useDispatch } from 'react-redux';
import { ACTIVITY_CREATE_REQUEST, CLOSE_NEW_RECORD_MENU } from 'state/actions';
import { CLOSE_NEW_RECORD_MENU } from 'state/actions';
import { ActivitySubtypeRelations, ActivitySubtypeShortLabels } from 'sharedAPI';

import './NewRecordDialog.css';
import UserSettings from 'state/actions/userSettings/UserSettings';
import { useSelector } from 'utils/use_selector';
import Activity from 'state/actions/activity/Activity';

export interface INewRecordDialog {}

Expand Down Expand Up @@ -72,10 +73,9 @@ const NewRecordDialog = (props: INewRecordDialog) => {
}, [newRecordDialogState.recordType]);

const insert_record = async () => {
dispatch({
type: ACTIVITY_CREATE_REQUEST,
payload: { type: newRecordDialogState.recordType, subType: newRecordDialogState.recordSubtype }
});
dispatch(
Activity.createReq({ type: newRecordDialogState.recordType, subType: newRecordDialogState.recordSubtype })
);
history.push('/Records/Activity:/form');
};

Expand Down
44 changes: 0 additions & 44 deletions app/src/state/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ export const ACTIVITY_GET_INITIAL_STATE_REQUEST = 'ACTIVITY_GET_INITIAL_STATE_RE
export const ACTIVITY_GET_INITIAL_STATE_SUCCESS = 'ACTIVITY_GET_INITIAL_STATE_SUCCESS';
export const ACTIVITY_GET_INITIAL_STATE_FAILURE = 'ACTIVITY_GET_INITIAL_STATE_FAILURE';

export const ACTIVITY_GET_REQUEST = 'ACTIVITY_GET_REQUEST';
export const ACTIVITY_GET_NETWORK_REQUEST = 'ACTIVITY_GET_NETWORK_REQUEST';
export const ACTIVITY_GET_LOCAL_REQUEST = 'ACTIVITY_GET_LOCALDB_REQUEST';
export const ACTIVITY_GET_SUCCESS = 'ACTIVITY_GET_SUCCESS';
export const ACTIVITY_GET_FAILURE = 'ACTIVITY_GET_FAILURE';

export const ACTIVITY_UPDATE_GEO_REQUEST = 'ACTIVITY_UPDATE_GEO_REQUEST';
export const ACTIVITY_UPDATE_GEO_SUCCESS = 'ACTIVITY_UPDATE_GEO_SUCCESS';
export const ACTIVITY_UPDATE_GEO_FAILURE = 'ACTIVITY_UPDATE_GEO_FAILURE';
Expand All @@ -63,9 +57,6 @@ export const ACTIVITY_ON_FORM_CHANGE_SUCCESS = 'ACTIVITY_ON_FORM_CHANGE_SUCCESS'
export const ACTIVITY_SET_CURRENT_HASH_REQUEST = 'ACTIVITY_SET_CURRENT_HASH_REQUEST';
export const ACTIVITY_SET_CURRENT_HASH_SUCCESS = 'ACTIVITY_SET_CURRENT_HASH_SUCCESS';
export const ACTIVITY_SET_CURRENT_HASH_FAILURE = 'ACTIVITY_SET_CURRENT_HASH_REQUEST';
export const ACTIVITY_SET_SAVED_HASH_REQUEST = 'ACTIVITY_SET_SAVED_HASH_REQUEST';
export const ACTIVITY_SET_SAVED_HASH_SUCCESS = 'ACTIVITY_SET_SAVED_HASH_SUCCESS';
export const ACTIVITY_SET_SAVED_HASH_FAILURE = 'ACTIVITY_SET_SAVED_HASH_REQUEST';

export const ACTIVITY_CHEM_TREATMENT_DETAILS_FORM_ON_CHANGE_REQUEST =
'ACTIVITY_CHEM_TREATMENT_DETAILS_FORM_ON_CHANGE_REQUEST';
Expand All @@ -84,17 +75,7 @@ export const ACTIVITY_PERSIST_REQUEST = 'ACTIVITY_PERSIST_REQUEST';
export const ACTIVITY_PERSIST_SUCCESS = 'ACTIVITY_PERSIST_SUCCESS';
export const ACTIVITY_PERSIST_FAILURE = 'ACTIVITY_PERSIST_FAILURE';

export const ACTIVITY_SAVE_REQUEST = 'ACTIVITY_SAVE_REQUEST';
export const ACTIVITY_SAVE_SUCCESS = 'ACTIVITY_SAVE_SUCCESS';

export const TOGGLE_CUSTOMIZE_LAYERS = 'TOGGLE_CUSTOMIZE_LAYERS';
export const ACTIVITY_PASTE_REQUEST = 'ACTIVITY_PASTE_REQUEST';
export const ACTIVITY_PASTE_SUCCESS = 'ACTIVITY_PASTE_SUCCESS';
export const ACTIVITY_PASTE_FAILURE = 'ACTIVITY_PASTE_FAILURE';

export const ACTIVITY_COPY_REQUEST = 'ACTIVITY_COPY_REQUEST';
export const ACTIVITY_COPY_SUCCESS = 'ACTIVITY_COPY_SUCCESS';
export const ACTIVITY_COPY_FAILURE = 'ACTIVITY_COPY_FAILURE';

export const ACTIVITY_SAVE_OFFLINE = 'ACTIVITY_SAVE_OFFLINE';
export const ACTIVITY_RESTORE_OFFLINE = 'ACTIVITY_RESTORE_OFFLINE';
Expand All @@ -105,28 +86,7 @@ export const ACTIVITY_OFFLINE_SYNC_DIALOG_SET_STATE = 'ACTIVITY_OFFLINE_SYNC_DIA
export const ACTIVITY_RUN_OFFLINE_SYNC = 'ACTIVITY_RUN_OFFLINE_SYNC';
export const ACTIVITY_RUN_OFFLINE_SYNC_COMPLETE = 'ACTIVITY_RUN_OFFLINE_SYNC_COMPLETE';

export const ACTIVITY_SAVE_NETWORK_REQUEST = 'ACTIVITY_SAVE_NETWORK_REQUEST';
export const ACTIVITY_SAVE_NETWORK_SUCCESS = 'ACTIVITY_SAVE_NETWORK_SUCCESS';
export const ACTIVITY_SAVE_NETWORK_FAILURE = 'ACTIVITY_SAVE_NETWORK_FAILURE';

export const ACTIVITY_CREATE_REQUEST = 'ACTIVITY_CREATE_REQUEST';
export const ACTIVITY_CREATE_NETWORK = 'ACTIVITY_CREATE_NETWORK';
export const ACTIVITY_CREATE_LOCAL = 'ACTIVITY_CREATE_LOCAL';
export const ACTIVITY_CREATE_SUCCESS = 'ACTIVITY_CREATE_SUCCESS';
export const ACTIVITY_CREATE_FAILURE = 'ACTIVITY_CREATE_FAILURE';

export const ACTIVITY_SUBMIT_REQUEST = 'ACTIVITY_SUBMIT_REQUEST';
export const ACTIVITY_SUBMIT_SUCCESS = 'ACTIVITY_SUBMIT_SUCCESS';
export const ACTIVITY_SUBMIT_FAILURE = 'ACTIVITY_SUBMIT_FAILURE';
export const ACTIVITY_DELETE_REQUEST = 'ACTIVITY_DELETE_REQUEST';
export const ACTIVITY_DELETE_NETWORK_REQUEST = 'ACTIVITY_DELETE_NETWORK_REQUEST';

export const PAN_AND_ZOOM_TO_ACTIVITY = 'PAN_AND_ZOOM_TO_ACTIVITY';
export const ACTIVITY_DELETE_SUCCESS = 'ACTIVITY_DELETE_SUCCESS';
export const ACTIVITY_DELETE_FAILURE = 'ACTIVITY_DELETE_FAILURE';
export const ACTIVITY_SET_ACTIVE_REQUEST = 'ACTIVITY_SET_ACTIVE_REQUEST';
export const ACTIVITY_SET_ACTIVE_SUCCESS = 'ACTIVITY_SET_ACTIVE_SUCCESS';
export const ACTIVITY_SET_ACTIVE_FAILURE = 'ACTIVITY_SET_ACTIVE_FAILURE';

export const ACTIVITY_DEBUG = 'ACTIVITY_DEBUG';

Expand Down Expand Up @@ -300,7 +260,3 @@ export const EMAIL_TEMPLATES_RETRIEVE_REQUEST_SUCCESS = 'EMAIL_TEMPLATES_RETRIEV
export const EMAIL_TEMPLATES_RETRIEVE_REQUEST_FAILURE = 'EMAIL_TEMPLATES_RETRIEVE_REQUEST_FAILURE';

export const CRASH_HANDLE_GLOBAL_ERROR = 'CRASH_HANDLE_GLOBAL_ERROR';

export const NEW_ALERT = 'NEW_ALERT';
export const CLEAR_ALERTS = 'CLEAR_ALERTS';
export const CLEAR_ALERT = 'CLEAR_ALERT';
141 changes: 38 additions & 103 deletions app/src/state/actions/activity/Activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,127 +2,62 @@ import { createAction } from '@reduxjs/toolkit';
import Offline from './Offline';
import Photos from './Photos';
import Suggestions from './Suggestions';
import {
ACTIVITY_LINK_RECORD_REQUEST,
ACTIVITY_LINK_RECORD_SUCCESS,
ACTIVITY_LINK_RECORD_FAILURE,
ACTIVITY_PERSIST_REQUEST,
ACTIVITY_PERSIST_SUCCESS,
ACTIVITY_PERSIST_FAILURE,
ACTIVITY_UPDATE_SYNC_STATE,
ACTIVITY_ERRORS,
ACTIVITY_DEBUG,
ACTIVITY_PAGE_MAP_EXTENT_TOGGLE,
ACTIVITY_UPDATE_GEO_REQUEST,
ACTIVITY_UPDATE_GEO_SUCCESS,
ACTIVITY_UPDATE_GEO_FAILURE,
ACTIVITY_GET_INITIAL_STATE_REQUEST,
ACTIVITY_GET_INITIAL_STATE_SUCCESS,
ACTIVITY_GET_INITIAL_STATE_FAILURE,
ACTIVITY_BUILD_SCHEMA_FOR_FORM_REQUEST,
ACTIVITY_BUILD_SCHEMA_FOR_FORM_SUCCESS,
ACTIVITY_ON_FORM_CHANGE_REQUEST,
ACTIVITY_ON_FORM_CHANGE_SUCCESS,
ACTIVITY_SET_CURRENT_HASH_REQUEST,
ACTIVITY_SET_CURRENT_HASH_SUCCESS,
ACTIVITY_SET_CURRENT_HASH_FAILURE,
ACTIVITY_CHEM_TREATMENT_DETAILS_FORM_ON_CHANGE_REQUEST,
ACTIVITY_CHEM_TREATMENT_DETAILS_FORM_ON_CHANGE_SUCCESS,
ACTIVITIES_TABLE_ROWS_GET_REQUEST,
ACTIVITIES_TABLE_ROWS_GET_ONLINE,
ACTIVITIES_TABLE_ROWS_GET_SUCCESS,
ACTIVITIES_TABLE_ROWS_GET_FAILURE,
ACTIVITIES_GET_IDS_FOR_RECORDSET_REQUEST,
ACTIVITIES_GET_IDS_FOR_RECORDSET_ONLINE,
ACTIVITIES_GET_IDS_FOR_RECORDSET_SUCCESS,
ACTIVITY_SET_ACTIVE_REQUEST,
ACTIVITY_SET_ACTIVE_SUCCESS,
ACTIVITY_SET_ACTIVE_FAILURE,
ACTIVITY_CREATE_REQUEST,
ACTIVITY_CREATE_NETWORK,
ACTIVITY_CREATE_LOCAL,
ACTIVITY_CREATE_SUCCESS,
ACTIVITY_CREATE_FAILURE,
ACTIVITY_DELETE_REQUEST,
ACTIVITY_DELETE_NETWORK_REQUEST,
ACTIVITY_DELETE_SUCCESS,
ACTIVITY_DELETE_FAILURE,
ACTIVITY_SUBMIT_REQUEST,
ACTIVITY_SUBMIT_SUCCESS,
ACTIVITY_SUBMIT_FAILURE,
ACTIVITY_SAVE_NETWORK_REQUEST,
ACTIVITY_SAVE_NETWORK_SUCCESS,
ACTIVITY_SAVE_NETWORK_FAILURE,
ACTIVITY_SAVE_REQUEST,
ACTIVITY_SAVE_SUCCESS,
ACTIVITY_SET_SAVED_HASH_REQUEST,
ACTIVITY_SET_SAVED_HASH_SUCCESS,
ACTIVITY_SET_SAVED_HASH_FAILURE,
ACTIVITY_GET_NETWORK_REQUEST,
ACTIVITY_PASTE_REQUEST,
ACTIVITY_PASTE_SUCCESS,
ACTIVITY_PASTE_FAILURE,
ACTIVITY_COPY_REQUEST,
ACTIVITY_COPY_SUCCESS,
ACTIVITY_COPY_FAILURE,
ACTIVITY_GET_REQUEST,
ACTIVITY_GET_LOCAL_REQUEST,
ACTIVITY_GET_SUCCESS,
ACTIVITY_GET_FAILURE
} from '../../actions';
import AutoFill from './AutoFill';
import GeoJson from './GeoJson';
import { ActivityStatus } from 'sharedAPI';

export interface INewActivity {
type: string;
subType: string;
}
interface ISaveNetwork {
activity_id: string;
updatedFormData?: Record<string, any>;
form_status?: ActivityStatus;
}
export interface ICreateLocal {
id: string;
data: Record<string, any>;
}
class Activity {
private static readonly PREFIX = 'Activity';
static readonly Offline = Offline;
static readonly Photo = Photos;
static readonly Suggestions = Suggestions;
static readonly Autofill = AutoFill;
static readonly GeoJson = GeoJson;

static readonly createReq = createAction(ACTIVITY_CREATE_REQUEST);
static readonly createNetwork = createAction(ACTIVITY_CREATE_NETWORK);

static readonly saveNetworkRequest = createAction(ACTIVITY_SAVE_NETWORK_REQUEST);
static readonly saveNetworkSuccess = createAction(ACTIVITY_SAVE_NETWORK_SUCCESS);
static readonly saveNetworkFailure = createAction(ACTIVITY_SAVE_NETWORK_FAILURE);
static readonly getNetworkRequest = createAction(ACTIVITY_GET_NETWORK_REQUEST);
static readonly createReq = createAction<INewActivity>(`${this.PREFIX}/createReq`);
static readonly createNetwork = createAction<Record<string, any>>(`${this.PREFIX}/createNetwork`);

static readonly save = createAction(ACTIVITY_SAVE_REQUEST);
static readonly saveSuccess = createAction(ACTIVITY_SAVE_SUCCESS);
static readonly saveNetworkRequest = createAction<ISaveNetwork>(`${this.PREFIX}/saveNetworkRequest`);
static readonly getNetworkRequest = createAction<string>(`${this.PREFIX}/getNetworkRequest`);

static readonly setSavedHash = createAction(ACTIVITY_SET_SAVED_HASH_REQUEST);
static readonly setSavedHashSuccess = createAction(ACTIVITY_SET_SAVED_HASH_SUCCESS);
static readonly setSavedHashFailure = createAction(ACTIVITY_SET_SAVED_HASH_FAILURE);
static readonly save = createAction(`${this.PREFIX}/save`);
static readonly saveSuccess = createAction<Record<string, any>>(`${this.PREFIX}/saveSuccess`);

static readonly createLocal = createAction(ACTIVITY_CREATE_LOCAL);
static readonly createSuccess = createAction(ACTIVITY_CREATE_SUCCESS);
static readonly createFailure = createAction(ACTIVITY_CREATE_FAILURE);
static readonly setSavedHashSuccess = createAction<string>(`${this.PREFIX}/setSavedHashSuccess`);

static readonly deleteReq = createAction(ACTIVITY_DELETE_REQUEST);
static readonly deleteNetwork = createAction(ACTIVITY_DELETE_NETWORK_REQUEST);
static readonly deleteSuccess = createAction(ACTIVITY_DELETE_SUCCESS);
static readonly deleteFailure = createAction(ACTIVITY_DELETE_FAILURE);
static readonly createLocal = createAction<ICreateLocal>(`${this.PREFIX}/createLocal`);
static readonly createSuccess = createAction<string>(`${this.PREFIX}/createSuccess`);

static readonly submit = createAction(ACTIVITY_SUBMIT_REQUEST);
static readonly submitSuccess = createAction(ACTIVITY_SUBMIT_SUCCESS);
static readonly submitFailure = createAction(ACTIVITY_SUBMIT_FAILURE);
static readonly deleteReq = createAction(`${this.PREFIX}/deleteReq`);
static readonly deleteNetwork = createAction(`${this.PREFIX}/deleteNetwork`);
static readonly deleteSuccess = createAction(`${this.PREFIX}/deleteSuccess`);
static readonly deleteFailure = createAction(`${this.PREFIX}/deleteFailure`);

static readonly paste = createAction(ACTIVITY_PASTE_REQUEST);
static readonly pasteSuccess = createAction(ACTIVITY_PASTE_SUCCESS);
static readonly pasteFailure = createAction(ACTIVITY_PASTE_FAILURE);
static readonly submit = createAction(`${this.PREFIX}/submit`);

static readonly copy = createAction(ACTIVITY_COPY_REQUEST);
static readonly copySuccess = createAction(ACTIVITY_COPY_SUCCESS);
static readonly copyFailure = createAction(ACTIVITY_COPY_FAILURE);
static readonly paste = createAction(`${this.PREFIX}/paste`);

static readonly get = createAction(ACTIVITY_GET_REQUEST);
static readonly getLocal = createAction(ACTIVITY_GET_LOCAL_REQUEST);
static readonly getSuccess = createAction(ACTIVITY_GET_SUCCESS);
static readonly getFailure = createAction(ACTIVITY_GET_FAILURE);
static readonly copy = createAction(`${this.PREFIX}/copy`);
static readonly copySuccess = createAction<Record<string, any>>(`${this.PREFIX}/copySuccess`);

static readonly setActive = createAction(ACTIVITY_SET_ACTIVE_REQUEST);
static readonly setActiveSuccess = createAction(ACTIVITY_SET_ACTIVE_SUCCESS);
static readonly setActiveFailure = createAction(ACTIVITY_SET_ACTIVE_FAILURE);
static readonly get = createAction<string>(`${this.PREFIX}/get`);
static readonly getLocal = createAction<string>(`${this.PREFIX}/getLocal`);
static readonly getSuccess = createAction<Record<string, any>>(`${this.PREFIX}/getSuccess`);
static readonly getFailure = createAction(`${this.PREFIX}/getFailure`, (arg?: Response) => ({
payload: arg
}));
}
export default Activity;
Loading
Loading