From 409007e8201b70c976d291e9d66e6a4bf0311d17 Mon Sep 17 00:00:00 2001 From: Nishit Suwal <81785002+NSUWAL123@users.noreply.github.com> Date: Wed, 7 Aug 2024 22:02:30 +0545 Subject: [PATCH] refactor(frontend): additional upgrades javascript --> typescript (#1737) * fix(project): convert js to ts * fix(projectById): remove first argument from projectById action * fix(projectOptions): types add * fix(project): ts types add to project services * fix(submissions): store filterType seperately * feat(api): add ts types to remaining services * fix(dropdown): props fix * fix(submissionsTable): customSelect value props ts error fix --- src/frontend/src/api/CreateProjectService.ts | 48 +++++------ src/frontend/src/api/HomeService.ts | 2 +- src/frontend/src/api/Login.ts | 2 +- src/frontend/src/api/OrganisationService.ts | 10 +-- .../src/api/{Project.js => Project.ts} | 82 ++++++++++--------- src/frontend/src/api/ProjectTaskStatus.ts | 2 +- src/frontend/src/api/Submission.ts | 2 +- src/frontend/src/api/SubmissionService.ts | 7 +- .../ProjectDetailsV2/ProjectOptions.tsx | 4 +- .../ProjectSubmissions/SubmissionsTable.tsx | 15 +--- .../src/components/common/Dropdown.tsx | 8 +- src/frontend/src/store/types/ISubmissions.ts | 7 ++ src/frontend/src/views/ProjectDetailsV2.tsx | 4 +- src/frontend/src/views/ProjectSubmissions.tsx | 4 +- src/frontend/src/views/Submissions.tsx | 4 +- src/frontend/src/views/Tasks.tsx | 4 +- 16 files changed, 102 insertions(+), 103 deletions(-) rename src/frontend/src/api/{Project.js => Project.ts} (81%) diff --git a/src/frontend/src/api/CreateProjectService.ts b/src/frontend/src/api/CreateProjectService.ts index 9b7e9702b2..b2ee671d05 100755 --- a/src/frontend/src/api/CreateProjectService.ts +++ b/src/frontend/src/api/CreateProjectService.ts @@ -10,7 +10,7 @@ import { CommonActions } from '@/store/slices/CommonSlice'; import { ValidateCustomFormResponse } from '@/store/types/ICreateProject'; import { isStatusSuccess } from '@/utilfunctions/commonUtils'; -const CreateProjectService: Function = ( +const CreateProjectService = ( url: string, projectData: any, taskAreaGeojson: any, @@ -110,11 +110,11 @@ const CreateProjectService: Function = ( }; }; -const FormCategoryService: Function = (url: string) => { +const FormCategoryService = (url: string) => { return async (dispatch) => { dispatch(CreateProjectActions.GetFormCategoryLoading(true)); - const getFormCategoryList = async (url) => { + const getFormCategoryList = async (url: string) => { try { const getFormCategoryListResponse = await axios.get(url); const resp: FormCategoryListModel = getFormCategoryListResponse.data; @@ -128,10 +128,10 @@ const FormCategoryService: Function = (url: string) => { }; }; -const UploadTaskAreasService: Function = (url: string, filePayload: any, projectData: any) => { +const UploadTaskAreasService = (url: string, filePayload: any, projectData: any) => { return async (dispatch) => { dispatch(CreateProjectActions.UploadAreaLoading(true)); - const postUploadArea = async (url, filePayload) => { + const postUploadArea = async (url: string, filePayload: any) => { let isAPISuccess = true; try { const areaFormData = new FormData(); @@ -169,7 +169,7 @@ const UploadTaskAreasService: Function = (url: string, filePayload: any, project }; }; -const GenerateProjectFilesService: Function = (url: string, projectData: any, formUpload: any) => { +const GenerateProjectFilesService = (url: string, projectData: any, formUpload: any) => { return async (dispatch) => { dispatch(CreateProjectActions.GenerateProjectLoading(true)); dispatch(CommonActions.SetLoading(true)); @@ -221,11 +221,11 @@ const GenerateProjectFilesService: Function = (url: string, projectData: any, fo }; }; -const OrganisationService: Function = (url: string) => { +const OrganisationService = (url: string) => { return async (dispatch) => { dispatch(CreateProjectActions.GetOrganisationListLoading(true)); - const getOrganisationList = async (url) => { + const getOrganisationList = async (url: string) => { try { const getOrganisationListResponse = await axios.get(url); const resp: OrganisationListModel = getOrganisationListResponse.data; @@ -239,11 +239,11 @@ const OrganisationService: Function = (url: string) => { }; }; -const GetDividedTaskFromGeojson: Function = (url: string, projectData: any) => { +const GetDividedTaskFromGeojson = (url: string, projectData: Record) => { return async (dispatch) => { dispatch(CreateProjectActions.SetDividedTaskFromGeojsonLoading(true)); - const getDividedTaskFromGeojson = async (url, projectData) => { + const getDividedTaskFromGeojson = async (url: string, projectData: Record) => { try { const dividedTaskFormData = new FormData(); dividedTaskFormData.append('project_geojson', projectData.geojson); @@ -265,13 +265,13 @@ const GetDividedTaskFromGeojson: Function = (url: string, projectData: any) => { }; }; -const GetIndividualProjectDetails: Function = (url: string, projectData: any) => { +const GetIndividualProjectDetails = (url: string) => { return async (dispatch) => { dispatch(CreateProjectActions.SetIndividualProjectDetailsLoading(true)); - const getIndividualProjectDetails = async (url, projectData) => { + const getIndividualProjectDetails = async (url: string) => { try { - const getIndividualProjectDetailsResponse = await axios.get(url, { params: projectData }); + const getIndividualProjectDetailsResponse = await axios.get(url); const resp: ProjectDetailsModel = getIndividualProjectDetailsResponse.data; const formattedOutlineGeojson = { type: 'FeatureCollection', features: [{ ...resp.outline_geojson, id: 1 }] }; const modifiedResponse = { @@ -292,11 +292,11 @@ const GetIndividualProjectDetails: Function = (url: string, projectData: any) => } }; - await getIndividualProjectDetails(url, projectData); + await getIndividualProjectDetails(url); }; }; -const TaskSplittingPreviewService: Function = ( +const TaskSplittingPreviewService = ( url: string, projectAoiFile: any, no_of_buildings: string, @@ -305,7 +305,7 @@ const TaskSplittingPreviewService: Function = ( return async (dispatch) => { dispatch(CreateProjectActions.GetTaskSplittingPreviewLoading(true)); - const getTaskSplittingGeojson = async (url, projectAoiFile, dataExtractFile) => { + const getTaskSplittingGeojson = async (url: string, projectAoiFile: any, dataExtractFile: any) => { try { const taskSplittingFileFormData = new FormData(); taskSplittingFileFormData.append('project_geojson', projectAoiFile); @@ -343,11 +343,11 @@ const TaskSplittingPreviewService: Function = ( await getTaskSplittingGeojson(url, projectAoiFile, dataExtractFile); }; }; -const PatchProjectDetails: Function = (url: string, projectData: any) => { +const PatchProjectDetails = (url: string, projectData: Record) => { return async (dispatch) => { dispatch(CreateProjectActions.SetPatchProjectDetailsLoading(true)); - const patchProjectDetails = async (url, projectData) => { + const patchProjectDetails = async (url: string, projectData: Record) => { try { const getIndividualProjectDetailsResponse = await axios.patch(url, projectData); const resp: ProjectDetailsModel = getIndividualProjectDetailsResponse.data; @@ -373,11 +373,11 @@ const PatchProjectDetails: Function = (url: string, projectData: any) => { }; }; -const PostFormUpdate: Function = (url: string, projectData: any) => { +const PostFormUpdate = (url: string, projectData: Record) => { return async (dispatch) => { dispatch(CreateProjectActions.SetPostFormUpdateLoading(true)); - const postFormUpdate = async (url, projectData) => { + const postFormUpdate = async (url: string, projectData: Record) => { try { const formFormData = new FormData(); formFormData.append('xform_id', projectData.xformId); @@ -415,11 +415,11 @@ const PostFormUpdate: Function = (url: string, projectData: any) => { await postFormUpdate(url, projectData); }; }; -const EditProjectBoundaryService: Function = (url: string, geojsonUpload: any, dimension: any) => { +const EditProjectBoundaryService = (url: string, geojsonUpload: any, dimension: any) => { return async (dispatch) => { dispatch(CreateProjectActions.SetEditProjectBoundaryServiceLoading(true)); - const postFormUpdate = async (url, geojsonUpload, dimension) => { + const postFormUpdate = async (url: string, geojsonUpload: any, dimension: any) => { try { const editBoundaryFormData = new FormData(); editBoundaryFormData.append('project_geojson', geojsonUpload); @@ -450,7 +450,7 @@ const EditProjectBoundaryService: Function = (url: string, geojsonUpload: any, d }; }; -const ValidateCustomForm: Function = (url: string, formUpload: any) => { +const ValidateCustomForm = (url: string, formUpload: any) => { return async (dispatch) => { dispatch(CreateProjectActions.ValidateCustomFormLoading(true)); @@ -492,7 +492,7 @@ const ValidateCustomForm: Function = (url: string, formUpload: any) => { }; }; -const DeleteProjectService: Function = (url: string, hasRedirect: boolean = true) => { +const DeleteProjectService = (url: string, hasRedirect: boolean = true) => { return async (dispatch) => { const deleteProject = async (url: string) => { try { diff --git a/src/frontend/src/api/HomeService.ts b/src/frontend/src/api/HomeService.ts index cb7b1741a1..783a6f228e 100755 --- a/src/frontend/src/api/HomeService.ts +++ b/src/frontend/src/api/HomeService.ts @@ -5,7 +5,7 @@ export const HomeSummaryService: Function = (url: string) => { return async (dispatch) => { dispatch(HomeActions.HomeProjectLoading(true)); - const fetchHomeSummaries = async (url) => { + const fetchHomeSummaries = async (url: string) => { try { const fetchHomeData = await axios.get(url); const projectSummaries: any = fetchHomeData.data.results; diff --git a/src/frontend/src/api/Login.ts b/src/frontend/src/api/Login.ts index bd559c0af7..e954220ffb 100644 --- a/src/frontend/src/api/Login.ts +++ b/src/frontend/src/api/Login.ts @@ -5,7 +5,7 @@ import { LoginActions } from '@/store/slices/LoginSlice'; export const TemporaryLoginService: Function = (url: string) => { return async (dispatch) => { - const getTemporaryLogin = async (url) => { + const getTemporaryLogin = async (url: string) => { // Sets a cookie in the browser that is used for auth await axios.get(url); diff --git a/src/frontend/src/api/OrganisationService.ts b/src/frontend/src/api/OrganisationService.ts index 341876f393..7bb22728ad 100644 --- a/src/frontend/src/api/OrganisationService.ts +++ b/src/frontend/src/api/OrganisationService.ts @@ -6,7 +6,7 @@ import { OrganisationAction } from '@/store/slices/organisationSlice'; import { API } from '.'; import { LoginActions } from '@/store/slices/LoginSlice'; -function appendObjectToFormData(formData, object) { +function appendObjectToFormData(formData: FormData, object: Record) { for (const [key, value] of Object.entries(object)) { // if (key === 'logo') { // formData.append(key, value[0]) @@ -19,7 +19,7 @@ export const OrganisationService: Function = (url: string, payload: Organisation return async (dispatch) => { dispatch(CommonActions.PostOrganisationLoading(true)); - const postOrganisation = async (url, payload) => { + const postOrganisation = async (url: string, payload: OrganisationModal) => { try { const generateApiFormData = new FormData(); appendObjectToFormData(generateApiFormData, payload); @@ -43,7 +43,7 @@ export const OrganisationService: Function = (url: string, payload: Organisation export const OrganisationDataService: Function = (url: string) => { return async (dispatch) => { dispatch(OrganisationAction.GetOrganisationDataLoading(true)); - const getOrganisationData = async (url) => { + const getOrganisationData = async (url: string) => { try { const getOrganisationDataResponse = await API.get(url); const response: GetOrganisationDataModel = getOrganisationDataResponse.data; @@ -63,7 +63,7 @@ export const OrganisationDataService: Function = (url: string) => { export const MyOrganisationDataService: Function = (url: string) => { return async (dispatch) => { dispatch(OrganisationAction.GetMyOrganisationDataLoading(true)); - const getMyOrganisationData = async (url) => { + const getMyOrganisationData = async (url: string) => { try { const getMyOrganisationDataResponse = await API.get(url); const response: GetOrganisationDataModel[] = getMyOrganisationDataResponse.data; @@ -126,7 +126,7 @@ export const PostOrganisationDataService: Function = (url: string, payload: any) export const GetIndividualOrganizationService: Function = (url: string) => { return async (dispatch) => { dispatch(OrganisationAction.SetOrganisationFormData({})); - const getOrganisationData = async (url) => { + const getOrganisationData = async (url: string) => { try { const getOrganisationDataResponse = await axios.get(url); const response: GetOrganisationDataModel = getOrganisationDataResponse.data; diff --git a/src/frontend/src/api/Project.js b/src/frontend/src/api/Project.ts similarity index 81% rename from src/frontend/src/api/Project.js rename to src/frontend/src/api/Project.ts index e0af1a0d56..99f4219c7e 100755 --- a/src/frontend/src/api/Project.js +++ b/src/frontend/src/api/Project.ts @@ -2,17 +2,17 @@ import { ProjectActions } from '@/store/slices/ProjectSlice'; import { CommonActions } from '@/store/slices/CommonSlice'; import CoreModules from '@/shared/CoreModules'; import { task_status } from '@/types/enums'; -import axios from 'axios'; import { writeBinaryToOPFS } from '@/api/Files'; +import { projectInfoType } from '@/models/project/projectModel'; -export const ProjectById = (existingProjectList, projectId) => { +export const ProjectById = (projectId: string) => { return async (dispatch) => { - const fetchProjectById = async (projectId, existingProjectList) => { + const fetchProjectById = async (projectId: string) => { try { dispatch(ProjectActions.SetProjectDetialsLoading(true)); const project = await CoreModules.axios.get(`${import.meta.env.VITE_API_URL}/projects/${projectId}`); - const projectResp = project.data; - const persistingValues = projectResp.tasks.map((data) => { + const projectResp: Record = project.data; + const persistingValues: Record = projectResp.tasks.map((data) => { return { id: data.id, index: data.project_task_index, @@ -65,19 +65,19 @@ export const ProjectById = (existingProjectList, projectId) => { } }; - await fetchProjectById(projectId, existingProjectList); + await fetchProjectById(projectId); dispatch(ProjectActions.SetNewProjectTrigger()); }; }; -export const DownloadProjectForm = (url, payload, projectId) => { +export const DownloadProjectForm = (url: string, downloadType: 'form' | 'geojson', projectId: string) => { return async (dispatch) => { - dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: payload, loading: true })); + dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: downloadType, loading: true })); - const fetchProjectForm = async (url, payload, projectId) => { + const fetchProjectForm = async (url: string, downloadType: 'form' | 'geojson', projectId: string) => { try { let response; - if (payload === 'form') { + if (downloadType === 'form') { response = await CoreModules.axios.get(url, { responseType: 'blob' }); } else { response = await CoreModules.axios.get(url, { @@ -86,26 +86,28 @@ export const DownloadProjectForm = (url, payload, projectId) => { } const a = document.createElement('a'); a.href = window.URL.createObjectURL(response.data); - a.download = `${payload === 'form' ? `project_form_${projectId}.xls` : `task_polygons_${projectId}.geojson`}`; + a.download = `${ + downloadType === 'form' ? `project_form_${projectId}.xls` : `task_polygons_${projectId}.geojson` + }`; a.click(); - dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: payload, loading: false })); + dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: downloadType, loading: false })); } catch (error) { - dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: payload, loading: false })); + dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: downloadType, loading: false })); } finally { - dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: payload, loading: false })); + dispatch(ProjectActions.SetDownloadProjectFormLoading({ type: downloadType, loading: false })); } }; - await fetchProjectForm(url, payload, projectId); + await fetchProjectForm(url, downloadType, projectId); }; }; -export const DownloadDataExtract = (url, payload) => { + +export const DownloadDataExtract = (url: string) => { return async (dispatch) => { dispatch(ProjectActions.SetDownloadDataExtractLoading(true)); - const getDownloadExtract = async (url, payload) => { + const getDownloadExtract = async (url: string) => { try { let response; - response = await CoreModules.axios.get(url, { responseType: 'blob', }); @@ -120,14 +122,15 @@ export const DownloadDataExtract = (url, payload) => { dispatch(ProjectActions.SetDownloadDataExtractLoading(false)); } }; - await getDownloadExtract(url, payload); + await getDownloadExtract(url); }; }; -export const GetTilesList = (url) => { + +export const GetTilesList = (url: string) => { return async (dispatch) => { dispatch(ProjectActions.SetTilesListLoading(true)); - const fetchTilesList = async (url) => { + const fetchTilesList = async (url: string) => { try { const response = await CoreModules.axios.get(url); dispatch(ProjectActions.SetTilesList(response.data)); @@ -141,11 +144,12 @@ export const GetTilesList = (url) => { await fetchTilesList(url); }; }; -export const GenerateProjectTiles = (url, payload) => { + +export const GenerateProjectTiles = (url: string, payload: string) => { return async (dispatch) => { dispatch(ProjectActions.SetGenerateProjectTilesLoading(true)); - const generateProjectTiles = async (url, payload) => { + const generateProjectTiles = async (url: string, payload: string) => { try { const response = await CoreModules.axios.get(url); dispatch(GetTilesList(`${import.meta.env.VITE_API_URL}/projects/${payload}/tiles-list/`)); @@ -160,11 +164,11 @@ export const GenerateProjectTiles = (url, payload) => { }; }; -export const DownloadTile = (url, payload, toOpfs = false) => { +export const DownloadTile = (url: string, payload: Partial, toOpfs: boolean = false) => { return async (dispatch) => { dispatch(ProjectActions.SetDownloadTileLoading({ type: payload, loading: true })); - const getDownloadTile = async (url, payload, toOpfs) => { + const getDownloadTile = async (url: string, payload: Partial, toOpfs: boolean) => { try { const response = await CoreModules.axios.get(url, { responseType: 'arraybuffer', @@ -208,9 +212,9 @@ export const DownloadTile = (url, payload, toOpfs = false) => { }; }; -export const GetProjectDashboard = (url) => { +export const GetProjectDashboard = (url: string) => { return async (dispatch) => { - const getProjectDashboard = async (url) => { + const getProjectDashboard = async (url: string) => { try { dispatch(ProjectActions.SetProjectDashboardLoading(true)); const response = await CoreModules.axios.get(url); @@ -226,9 +230,9 @@ export const GetProjectDashboard = (url) => { }; }; -export const GetEntityInfo = (url) => { +export const GetEntityInfo = (url: string) => { return async (dispatch) => { - const getEntityOsmMap = async (url) => { + const getEntityOsmMap = async (url: string) => { try { dispatch(ProjectActions.SetEntityToOsmIdMappingLoading(true)); dispatch(CoreModules.TaskActions.SetTaskSubmissionStatesLoading(true)); @@ -248,9 +252,9 @@ export const GetEntityInfo = (url) => { }; }; -export const GetProjectComments = (url) => { +export const GetProjectComments = (url: string) => { return async (dispatch) => { - const getProjectComments = async (url) => { + const getProjectComments = async (url: string) => { try { dispatch(ProjectActions.SetProjectGetCommentsLoading(true)); const response = await CoreModules.axios.get(url); @@ -266,9 +270,9 @@ export const GetProjectComments = (url) => { }; }; -export const PostProjectComments = (url, payload) => { +export const PostProjectComments = (url: string, payload: { task_id: number; project_id: any; comment: string }) => { return async (dispatch) => { - const postProjectComments = async (url) => { + const postProjectComments = async (url: string) => { try { dispatch(ProjectActions.SetPostProjectCommentsLoading(true)); const response = await CoreModules.axios.post(url, payload); @@ -284,9 +288,9 @@ export const PostProjectComments = (url, payload) => { }; }; -export const GetProjectTaskActivity = (url) => { +export const GetProjectTaskActivity = (url: string) => { return async (dispatch) => { - const getProjectActivity = async (url) => { + const getProjectActivity = async (url: string) => { try { dispatch(ProjectActions.SetProjectTaskActivityLoading(true)); const response = await CoreModules.axios.get(url); @@ -302,9 +306,9 @@ export const GetProjectTaskActivity = (url) => { }; }; -export const UpdateEntityStatus = (url, payload) => { +export const UpdateEntityStatus = (url: string, payload: { entity_id: string; status: number; label: string }) => { return async (dispatch) => { - const updateEntityStatus = async (url, payload) => { + const updateEntityStatus = async (url: string, payload: { entity_id: string; status: number; label: string }) => { try { dispatch(ProjectActions.UpdateEntityStatusLoading(true)); const response = await CoreModules.axios.post(url, payload); @@ -318,11 +322,11 @@ export const UpdateEntityStatus = (url, payload) => { }; }; -export const DownloadSubmissionGeojson = (url, projectName) => { +export const DownloadSubmissionGeojson = (url: string, projectName: string) => { return async (dispatch) => { dispatch(ProjectActions.SetDownloadSubmissionGeojsonLoading(true)); - const downloadSubmissionGeojson = async (url) => { + const downloadSubmissionGeojson = async (url: string) => { try { const response = await CoreModules.axios.get(url, { responseType: 'blob' }); const a = document.createElement('a'); diff --git a/src/frontend/src/api/ProjectTaskStatus.ts b/src/frontend/src/api/ProjectTaskStatus.ts index df747bef00..a87aff019a 100755 --- a/src/frontend/src/api/ProjectTaskStatus.ts +++ b/src/frontend/src/api/ProjectTaskStatus.ts @@ -15,7 +15,7 @@ const UpdateTaskStatus = ( params: { project_id: string }, ) => { return async (dispatch) => { - const updateTask = async (url: string, body: any, feature: Record, params: string) => { + const updateTask = async (url: string, body: any, feature: Record, params: { project_id: string }) => { try { dispatch(CommonActions.SetLoading(true)); diff --git a/src/frontend/src/api/Submission.ts b/src/frontend/src/api/Submission.ts index 6ba74b31dc..5ec195a0be 100644 --- a/src/frontend/src/api/Submission.ts +++ b/src/frontend/src/api/Submission.ts @@ -4,7 +4,7 @@ import { SubmissionActions } from '@/store/slices/SubmissionSlice'; export const SubmissionService: Function = (url: string) => { return async (dispatch) => { dispatch(SubmissionActions.SetSubmissionDetailsLoading(true)); - const getSubmissionDetails = async (url) => { + const getSubmissionDetails = async (url: string) => { try { const getSubmissionDetailsResponse = await axios.get(url); const response: any = getSubmissionDetailsResponse.data; diff --git a/src/frontend/src/api/SubmissionService.ts b/src/frontend/src/api/SubmissionService.ts index 89193a6931..02c9b770c9 100644 --- a/src/frontend/src/api/SubmissionService.ts +++ b/src/frontend/src/api/SubmissionService.ts @@ -1,9 +1,8 @@ import CoreModules from '@/shared/CoreModules'; import { CommonActions } from '@/store/slices/CommonSlice'; import { ProjectActions } from '@/store/slices/ProjectSlice'; -// import { HomeProjectCardModel } from '@/models/home/homeModel'; import { SubmissionActions } from '@/store/slices/SubmissionSlice'; -import { basicGeojsonTemplate } from '@/utilities/mapUtils'; +import { filterType } from '@/store/types/ISubmissions'; export const ProjectSubmissionService: Function = (url: string) => { return async (dispatch) => { @@ -62,9 +61,9 @@ export const SubmissionFormFieldsService: Function = (url: string) => { }; }; -export const SubmissionTableService: Function = (url: string, payload) => { +export const SubmissionTableService: Function = (url: string, payload: filterType) => { return async (dispatch) => { - const fetchSubmissionTable = async (url: string, payload) => { + const fetchSubmissionTable = async (url: string, payload: filterType) => { try { dispatch(SubmissionActions.SetSubmissionTableLoading(true)); const response = await CoreModules.axios.get(url, { params: payload }); diff --git a/src/frontend/src/components/ProjectDetailsV2/ProjectOptions.tsx b/src/frontend/src/components/ProjectDetailsV2/ProjectOptions.tsx index afc50cffd7..84e36adfdc 100644 --- a/src/frontend/src/components/ProjectDetailsV2/ProjectOptions.tsx +++ b/src/frontend/src/components/ProjectDetailsV2/ProjectOptions.tsx @@ -6,7 +6,7 @@ import Button from '@/components/common/Button'; import { useAppSelector } from '@/types/reduxTypes'; type projectOptionPropTypes = { - projectName: string | undefined; + projectName: string; }; const ProjectOptions = ({ projectName }: projectOptionPropTypes) => { @@ -19,7 +19,7 @@ const ProjectOptions = ({ projectName }: projectOptionPropTypes) => { const projectId: string = params.id; - const handleDownload = (downloadType) => { + const handleDownload = (downloadType: 'form' | 'geojson') => { if (downloadType === 'form') { dispatch( DownloadProjectForm( diff --git a/src/frontend/src/components/ProjectSubmissions/SubmissionsTable.tsx b/src/frontend/src/components/ProjectSubmissions/SubmissionsTable.tsx index 90637ee404..17ed993eb1 100644 --- a/src/frontend/src/components/ProjectSubmissions/SubmissionsTable.tsx +++ b/src/frontend/src/components/ProjectSubmissions/SubmissionsTable.tsx @@ -13,22 +13,15 @@ import CustomDatePicker from '@/components/common/CustomDatePicker'; import { format } from 'date-fns'; import Button from '@/components/common/Button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/common/Dropdown'; -import { ConvertXMLToJOSM, getDownloadProjectSubmission, getDownloadProjectSubmissionJson } from '@/api/task'; +import { ConvertXMLToJOSM, getDownloadProjectSubmission } from '@/api/task'; import { Modal } from '@/components/common/Modal'; import { useNavigate, useSearchParams } from 'react-router-dom'; import filterParams from '@/utilfunctions/filterParams'; import UpdateReviewStatusModal from '@/components/ProjectSubmissions/UpdateReviewStatusModal'; -import { projectInfoType } from '@/models/project/projectModel'; import { useAppSelector } from '@/types/reduxTypes'; import { camelToFlat } from '@/utilfunctions/commonUtils'; import useDocumentTitle from '@/utilfunctions/useDocumentTitle'; - -type filterType = { - task_id: string | null; - submitted_by: string | null; - review_state: string | null; - submitted_date: string | null; -}; +import { filterType } from '@/store/types/ISubmissions'; const SubmissionsTable = ({ toggleView }) => { useDocumentTitle('Submission Table'); @@ -262,7 +255,7 @@ const SubmissionsTable = ({ toggleView }) => { placeholder="Select" data={taskInfo} dataKey="value" - value={filter?.task_id?.toString() || null} + value={filter?.task_id?.toString() || undefined} valueKey="task_id" label="task_id" onValueChange={(value) => value && setFilter((prev) => ({ ...prev, task_id: value.toString() }))} @@ -275,7 +268,7 @@ const SubmissionsTable = ({ toggleView }) => { placeholder="Select" data={reviewStateData} dataKey="value" - value={filter?.review_state} + value={filter?.review_state || undefined} valueKey="value" label="label" onValueChange={(value) => diff --git a/src/frontend/src/components/common/Dropdown.tsx b/src/frontend/src/components/common/Dropdown.tsx index 6a586621b8..cd53bc30ac 100644 --- a/src/frontend/src/components/common/Dropdown.tsx +++ b/src/frontend/src/components/common/Dropdown.tsx @@ -39,10 +39,9 @@ const DropdownMenuSubContent = ({ className, ref, ...props }) => ( ); DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName; -const DropdownMenuContent = ({ className, sideOffset = 4, ref, ...props }) => ( +const DropdownMenuContent = ({ className, sideOffset = 4, ...props }) => ( ( ); DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName; -const DropdownMenuItem = ({ className, inset, ref, ...props }) => ( +const DropdownMenuItem = ({ ...props }) => ( diff --git a/src/frontend/src/store/types/ISubmissions.ts b/src/frontend/src/store/types/ISubmissions.ts index 6a26defc32..dde7ec2a05 100644 --- a/src/frontend/src/store/types/ISubmissions.ts +++ b/src/frontend/src/store/types/ISubmissions.ts @@ -26,3 +26,10 @@ type updateReviewStatusModal = { reviewState: string; taskUId: string | null; }; + +export type filterType = { + task_id: string | null; + submitted_by: string | null; + review_state: string | null; + submitted_date: string | null; +}; diff --git a/src/frontend/src/views/ProjectDetailsV2.tsx b/src/frontend/src/views/ProjectDetailsV2.tsx index 9b23bf358a..7327fafa68 100644 --- a/src/frontend/src/views/ProjectDetailsV2.tsx +++ b/src/frontend/src/views/ProjectDetailsV2.tsx @@ -105,10 +105,10 @@ const ProjectDetailsV2 = () => { dispatch(ProjectActions.SetNewProjectTrigger()); if (state.projectTaskBoundries.findIndex((project) => project.id.toString() === projectId) == -1) { dispatch(ProjectActions.SetProjectTaskBoundries([])); - dispatch(ProjectById(state.projectTaskBoundries, projectId)); + dispatch(ProjectById(projectId)); } else { dispatch(ProjectActions.SetProjectTaskBoundries([])); - dispatch(ProjectById(state.projectTaskBoundries, projectId)); + dispatch(ProjectById(projectId)); } if (Object.keys(state.projectInfo)?.length == 0) { dispatch(ProjectActions.SetProjectInfo(projectInfo)); diff --git a/src/frontend/src/views/ProjectSubmissions.tsx b/src/frontend/src/views/ProjectSubmissions.tsx index 56ba67c078..afa74d3c7d 100644 --- a/src/frontend/src/views/ProjectSubmissions.tsx +++ b/src/frontend/src/views/ProjectSubmissions.tsx @@ -27,10 +27,10 @@ const ProjectSubmissions = () => { dispatch(ProjectActions.SetNewProjectTrigger()); if (state.projectTaskBoundries.findIndex((project) => project.id == projectId) == -1) { dispatch(ProjectActions.SetProjectTaskBoundries([])); - dispatch(ProjectById(state.projectTaskBoundries, projectId)); + dispatch(ProjectById(projectId)); } else { dispatch(ProjectActions.SetProjectTaskBoundries([])); - dispatch(ProjectById(state.projectTaskBoundries, projectId)); + dispatch(ProjectById(projectId)); } if (Object.keys(state.projectInfo).length == 0) { dispatch(ProjectActions.SetProjectInfo(projectInfo)); diff --git a/src/frontend/src/views/Submissions.tsx b/src/frontend/src/views/Submissions.tsx index 6ade0fdd7f..b8fa478d95 100755 --- a/src/frontend/src/views/Submissions.tsx +++ b/src/frontend/src/views/Submissions.tsx @@ -29,10 +29,10 @@ const Submissions = () => { // Requesting Task Boundaries on Page Load useEffect(() => { if (state.projectTaskBoundries.findIndex((project) => project.id == projectId) == -1) { - dispatch(ProjectById(state.projectTaskBoundries, projectId)); + dispatch(ProjectById(projectId)); } else { dispatch(ProjectActions.SetProjectTaskBoundries([])); - dispatch(ProjectById(state.projectTaskBoundries, projectId)); + dispatch(ProjectById(projectId)); } if (Object.keys(state.projectInfo).length == 0) { dispatch(ProjectActions.SetProjectInfo(projectInfo)); diff --git a/src/frontend/src/views/Tasks.tsx b/src/frontend/src/views/Tasks.tsx index a4ee1243cf..1d239e3add 100644 --- a/src/frontend/src/views/Tasks.tsx +++ b/src/frontend/src/views/Tasks.tsx @@ -44,7 +44,7 @@ const TasksSubmission = () => { //Fetch project for the first time useEffect(() => { if (state.projectTaskBoundries.findIndex((project) => project.id == projectId) == -1) { - dispatch(ProjectById(state.projectTaskBoundries, projectId)); + dispatch(ProjectById(projectId)); // dispatch( // ProjectDataExtractService( // `${import.meta.env.VITE_API_URL}/projects/${projectId}/features`, @@ -52,7 +52,7 @@ const TasksSubmission = () => { // ); } else { dispatch(ProjectActions.SetProjectTaskBoundries([])); - dispatch(ProjectById(state.projectTaskBoundries, projectId)); + dispatch(ProjectById(projectId)); } if (Object.keys(state.projectInfo).length == 0) { dispatch(ProjectActions.SetProjectInfo(projectInfo));