diff --git a/src/frontend/src/store/slices/CommonSlice.ts b/src/frontend/src/store/slices/CommonSlice.ts index b3f9ddca23..7269cfd176 100755 --- a/src/frontend/src/store/slices/CommonSlice.ts +++ b/src/frontend/src/store/slices/CommonSlice.ts @@ -1,21 +1,25 @@ import CoreModules from '@/shared/CoreModules'; -const CommonSlice = CoreModules.createSlice({ - name: 'common', - initialState: { - snackbar: { - open: false, - message: '', - variant: 'info', - duration: 0, - }, - loading: false, - postOrganisationLoading: false, - currentStepFormStep: { - create_project: { - step: 1, - }, +import { CommonStateTypes } from '@/store/types/ICommon'; + +const initialState: CommonStateTypes = { + snackbar: { + open: false, + message: '', + variant: 'info', + duration: 0, + }, + loading: false, + postOrganisationLoading: false, + currentStepFormStep: { + create_project: { + step: 1, }, }, +}; + +const CommonSlice = CoreModules.createSlice({ + name: 'common', + initialState: initialState, reducers: { SetSnackBar(state, action) { state.snackbar = action.payload; diff --git a/src/frontend/src/store/slices/HomeSlice.ts b/src/frontend/src/store/slices/HomeSlice.ts index 430a7a0f21..1cc344d8df 100755 --- a/src/frontend/src/store/slices/HomeSlice.ts +++ b/src/frontend/src/store/slices/HomeSlice.ts @@ -1,21 +1,34 @@ import CoreModules from '@/shared/CoreModules'; +import { HomeStateTypes } from '@/store/types/IHome'; + +const initialState: HomeStateTypes = { + homeProjectSummary: [], + homeProjectLoading: true, + selectedProject: {}, + dialogStatus: false, + snackbar: { + open: false, + message: '', + variant: 'info', + duration: 0, + }, + showMapStatus: true, + projectCentroidLoading: false, + homeProjectPagination: { + has_next: false, + has_prev: false, + next_num: null, + page: null, + pages: null, + prev_num: null, + per_page: null, + total: null, + }, +}; + const HomeSlice = CoreModules.createSlice({ name: 'home', - initialState: { - homeProjectSummary: [], - homeProjectLoading: true, - selectedProject: {}, - dialogStatus: false, - snackbar: { - open: false, - message: '', - variant: 'info', - duration: 0, - }, - showMapStatus: true, - projectCentroidLoading: false, - homeProjectPagination: {}, - }, + initialState: initialState, reducers: { SetHomeProjectSummary(state, action) { state.homeProjectSummary = action.payload; diff --git a/src/frontend/src/store/slices/LoginSlice.ts b/src/frontend/src/store/slices/LoginSlice.ts index a829cc6ba5..fddc879990 100755 --- a/src/frontend/src/store/slices/LoginSlice.ts +++ b/src/frontend/src/store/slices/LoginSlice.ts @@ -1,11 +1,15 @@ import CoreModules from '@/shared/CoreModules'; import storage from 'redux-persist/lib/storage'; +import { LoginStateTypes } from '@/store/types/ILogin'; + +const initialState: LoginStateTypes = { + loginToken: {}, + authDetails: {}, +}; + const LoginSlice = CoreModules.createSlice({ name: 'login', - initialState: { - loginToken: {}, - authDetails: {}, - }, + initialState: initialState, reducers: { SetLoginToken(state, action) { state.loginToken = action.payload; diff --git a/src/frontend/src/store/slices/ProjectSlice.ts b/src/frontend/src/store/slices/ProjectSlice.ts index 352cd1a377..a620e9e1c0 100755 --- a/src/frontend/src/store/slices/ProjectSlice.ts +++ b/src/frontend/src/store/slices/ProjectSlice.ts @@ -1,29 +1,41 @@ import { createSlice } from '@reduxjs/toolkit'; import storage from 'redux-persist/lib/storage'; +import { ProjectStateTypes } from '@/store/types/IProject'; + +const initialState: ProjectStateTypes = { + projectLoading: true, + projectTaskBoundries: [], + newProjectTrigger: false, + projectInfo: {}, + projectSubmissionLoading: false, + projectSubmission: [], + projectDataExtractLoading: false, + downloadProjectFormLoading: { type: 'form', loading: false }, + generateProjectTilesLoading: false, + tilesList: [], + tilesListLoading: false, + downloadTilesLoading: false, + downloadDataExtractLoading: false, + taskModalStatus: false, + mobileFooterSelection: 'explore', + geolocationStatus: false, + projectDetailsLoading: true, + projectDashboardDetail: { + project_name_prefix: '', + organisation_name: '', + total_tasks: null, + created: '', + organisation_logo: '', + total_submission: null, + total_contributors: null, + last_active: '', + }, + projectDashboardLoading: false, +}; const ProjectSlice = createSlice({ name: 'project', - initialState: { - projectLoading: true, - projectTaskBoundries: [], - newProjectTrigger: false, - projectInfo: {}, - projectSubmissionLoading: false, - projectSubmission: [], - projectDataExtractLoading: false, - downloadProjectFormLoading: { type: 'form', loading: false }, - generateProjectTilesLoading: false, - tilesList: [], - tilesListLoading: false, - downloadTilesLoading: false, - downloadDataExtractLoading: false, - taskModalStatus: false, - mobileFooterSelection: 'explore', - geolocationStatus: false, - projectDetailsLoading: true, - projectDashboardDetail: {}, - projectDashboardLoading: false, - }, + initialState: initialState, reducers: { SetProjectTaskBoundries(state, action) { state.projectTaskBoundries = action.payload; diff --git a/src/frontend/src/store/slices/TaskSlice.ts b/src/frontend/src/store/slices/TaskSlice.ts index b15a726dc8..6a3aa0ed72 100644 --- a/src/frontend/src/store/slices/TaskSlice.ts +++ b/src/frontend/src/store/slices/TaskSlice.ts @@ -1,20 +1,23 @@ import { createSlice } from '@reduxjs/toolkit'; +import { TaskStateTypes, taskInfoType } from '@/store/types/ITask'; + +const initialState: TaskStateTypes = { + taskLoading: false, + taskInfo: [], + selectedTask: null, + projectBoundaryLoading: false, + projectBoundary: [], + convertToOsmLoading: false, + convertToOsm: [], + downloadSubmissionLoading: { type: '', loading: false }, + convertXMLToJOSMLoading: false, + josmEditorError: null, + taskData: { feature_count: 0, submission_count: 0, task_count: 0 }, +}; const TaskSlice = createSlice({ name: 'task', - initialState: { - taskLoading: false, - taskInfo: [], - selectedTask: null, - projectBoundaryLoading: false, - projectBoundary: [], - convertToOsmLoading: null, - convertToOsm: [], - downloadSubmissionLoading: { type: '', loading: false }, - convertXMLToJOSMLoading: false, - josmEditorError: null, - taskData: { feature_count: 0, submission_count: 0, task_count: 0 }, - }, + initialState: initialState, reducers: { SetTaskLoading(state, action) { state.taskLoading = action.payload; @@ -26,7 +29,7 @@ const TaskSlice = createSlice({ state.convertToOsmLoading = action.payload; }, FetchTaskInfoDetails(state, action) { - const taskInfo = action.payload; + const taskInfo: taskInfoType[] = action.payload; state.taskInfo = taskInfo; diff --git a/src/frontend/src/store/types/ICommon.ts b/src/frontend/src/store/types/ICommon.ts new file mode 100644 index 0000000000..83ad79f385 --- /dev/null +++ b/src/frontend/src/store/types/ICommon.ts @@ -0,0 +1,17 @@ +export type CommonStateTypes = { + snackbar: snackbarTypes; + loading: boolean; + postOrganisationLoading: boolean; + currentStepFormStep: { + create_project: { + step: number; + }; + }; +}; + +type snackbarTypes = { + open: boolean; + message: string; + variant: 'info' | 'success' | 'error' | 'warning'; + duration: number; +}; diff --git a/src/frontend/src/store/types/IHome.ts b/src/frontend/src/store/types/IHome.ts new file mode 100644 index 0000000000..91a83c7a24 --- /dev/null +++ b/src/frontend/src/store/types/IHome.ts @@ -0,0 +1,45 @@ +export type HomeStateTypes = { + homeProjectSummary: homeProjectSummaryType[]; + selectedProject: homeProjectSummaryType; + homeProjectLoading: boolean; + dialogStatus: boolean; + snackbar: snackbarTypes; + showMapStatus: boolean; + projectCentroidLoading: boolean; + homeProjectPagination: homeProjectPaginationTypes; +}; + +type homeProjectSummaryType = { + centroid?: [number, number]; + description?: string; + hashtags?: string | null; + id?: number; + location_str?: string; + num_contributors?: number; + organisation_id?: number; + organisation_logo?: string | null; + priority?: number; + tasks_bad?: number; + tasks_mapped?: number; + tasks_validated?: number; + title?: string; + total_tasks?: number; +}; + +type snackbarTypes = { + open: boolean; + message: string; + variant: 'info' | 'success' | 'error' | 'warning'; + duration: number; +}; + +type homeProjectPaginationTypes = { + has_next: boolean; + has_prev: boolean; + next_num: number | null; + page: number | null; + pages: number | null; + prev_num: number | null; + per_page: number | null; + total: number | null; +}; diff --git a/src/frontend/src/store/types/ILogin.ts b/src/frontend/src/store/types/ILogin.ts new file mode 100644 index 0000000000..84b59759e8 --- /dev/null +++ b/src/frontend/src/store/types/ILogin.ts @@ -0,0 +1,13 @@ +export type LoginStateTypes = { + loginToken: logintTokenType | {}; + authDetails: {} | string; +}; + +type logintTokenType = { + id: string; + osm_oauth_token: string; + picture: string; + role: string; + sessionToken: string | null; + username: string; +}; diff --git a/src/frontend/src/store/types/IProject.ts b/src/frontend/src/store/types/IProject.ts new file mode 100644 index 0000000000..88a1b6f873 --- /dev/null +++ b/src/frontend/src/store/types/IProject.ts @@ -0,0 +1,114 @@ +export type ProjectStateTypes = { + projectLoading: boolean; + projectTaskBoundries: projectTaskBoundriesType[]; + newProjectTrigger: boolean; + projectInfo: projectInfoType | {}; + projectSubmissionLoading: boolean; + projectSubmission: []; + projectDataExtractLoading: boolean; + downloadProjectFormLoading: downloadProjectFormLoadingType; + generateProjectTilesLoading: boolean; + tilesList: tilesListTypes[]; + tilesListLoading: boolean; + downloadTilesLoading: boolean; + downloadDataExtractLoading: boolean; + taskModalStatus: boolean; + mobileFooterSelection: string; + geolocationStatus: boolean; + projectDetailsLoading: boolean; + projectDashboardDetail: projectDashboardDetailTypes; + projectDashboardLoading: boolean; +}; + +type projectTaskBoundriesType = { + id: number; + taskBoundries: taskBoundriesTypes[]; +}; + +type taskBoundriesTypes = { + bbox: [number, number]; + id: number; + locked_by_uid: null | string; + locked_by_username: null | string; + odk_token: string; + outline_geojson: { + type: string; + geometry: { + coordinates: [string, string]; + type: string; + }; + properties: Record; + id: string; + bbox: [string, string, string, string]; + }; + outline_centroid: { + type: string; + geometry: { + coordinates: [string, string]; + type: string; + }; + properties: Record; + id: string; + bbox: [string, string, string, string]; + }; + task_history: taskHistoryTypes[]; + task_status: string; +}; + +type projectInfoType = { + id: number; + outline_geojson: { + type: string; + geometry: { + type: string; + coordinates: []; + }; + properties: { + id: number; + bbox: [number, number, number, number]; + }; + id: number; + }; + priority: number; + priority_str: string; + title: string; + location_str: string; + description: string; + short_description: string; + xform_title: string; + data_extract_url: string; + num_contributors: any; + tasks_bad: any; + tasks_mapped: any; + tasks_validated: any; + total_tasks: any; +}; + +type taskHistoryTypes = { + action_date: string; + action_text: string; + id: number; + profile_img: null | string; + status: string; + username: string; +}; + +type downloadProjectFormLoadingType = { type: 'form' | 'geojson'; loading: boolean }; + +type tilesListTypes = { + id: number; + project_id: number; + status: string; + tile_source: string; +}; + +type projectDashboardDetailTypes = { + project_name_prefix: string; + organisation_name: string; + total_tasks: number | null; + created: string; + organisation_logo: string; + total_submission: number | null; + total_contributors: number | null; + last_active: string; +}; diff --git a/src/frontend/src/store/types/ISubmissions.ts b/src/frontend/src/store/types/ISubmissions.ts index 1aa6a165f9..aa443085a6 100644 --- a/src/frontend/src/store/types/ISubmissions.ts +++ b/src/frontend/src/store/types/ISubmissions.ts @@ -1,15 +1,39 @@ export type SubmissionStateTypes = { submissionDetailsLoading: boolean; submissionDetails: []; - submissionInfographics: []; + submissionInfographics: submissionInfographicsTypes[]; submissionInfographicsLoading: boolean; - submissionContributors: []; + submissionContributors: submissionContributorsTypes[]; submissionContributorsLoading: boolean; - submissionFormFields: []; + submissionFormFields: submissionFormFieldsTypes[]; submissionTableData: []; submissionFormFieldsLoading: boolean; submissionTableDataLoading: boolean; submissionTableRefreshing: boolean; - validatedVsMappedInfographics: []; + validatedVsMappedInfographics: validatedVsMappedInfographicsTypes[]; validatedVsMappedLoading: boolean; }; + +type submissionInfographicsTypes = { + date: string; + count: 1; +}; + +type submissionContributorsTypes = { + user: string; + contributions: number; +}; + +type submissionFormFieldsTypes = { + path: string; + name: string; + type: string; + binary: any; + selectMultiple: any; +}; + +type validatedVsMappedInfographicsTypes = { + date: string; + validated: number; + mapped: number; +}; diff --git a/src/frontend/src/store/types/ITask.ts b/src/frontend/src/store/types/ITask.ts new file mode 100644 index 0000000000..758e410e0b --- /dev/null +++ b/src/frontend/src/store/types/ITask.ts @@ -0,0 +1,31 @@ +export type TaskStateTypes = { + taskLoading: boolean; + taskInfo: taskInfoType[]; + selectedTask: number | null; + projectBoundaryLoading: boolean; + projectBoundary: []; + convertToOsmLoading: boolean; + convertToOsm: []; + downloadSubmissionLoading: downloadSubmissionLoadingTypes; + convertXMLToJOSMLoading: boolean; + josmEditorError: null | string; + taskData: taskDataTypes; +}; + +export type taskInfoType = { + task_id: string; + submission_count: number; + last_submission: string | null; + feature_count: number; +}; + +type downloadSubmissionLoadingTypes = { + type: '' | 'json' | 'csv'; + loading: boolean; +}; + +type taskDataTypes = { + feature_count: number; + submission_count: number; + task_count: number; +};