Skip to content

Commit

Permalink
refactor(frontend): additional upgrades javascript --> typescript (#1737
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
NSUWAL123 authored Aug 7, 2024
1 parent ab716e0 commit 409007e
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 103 deletions.
48 changes: 24 additions & 24 deletions src/frontend/src/api/CreateProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -239,11 +239,11 @@ const OrganisationService: Function = (url: string) => {
};
};

const GetDividedTaskFromGeojson: Function = (url: string, projectData: any) => {
const GetDividedTaskFromGeojson = (url: string, projectData: Record<string, any>) => {
return async (dispatch) => {
dispatch(CreateProjectActions.SetDividedTaskFromGeojsonLoading(true));

const getDividedTaskFromGeojson = async (url, projectData) => {
const getDividedTaskFromGeojson = async (url: string, projectData: Record<string, any>) => {
try {
const dividedTaskFormData = new FormData();
dividedTaskFormData.append('project_geojson', projectData.geojson);
Expand All @@ -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 = {
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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<string, any>) => {
return async (dispatch) => {
dispatch(CreateProjectActions.SetPatchProjectDetailsLoading(true));

const patchProjectDetails = async (url, projectData) => {
const patchProjectDetails = async (url: string, projectData: Record<string, any>) => {
try {
const getIndividualProjectDetailsResponse = await axios.patch(url, projectData);
const resp: ProjectDetailsModel = getIndividualProjectDetailsResponse.data;
Expand All @@ -373,11 +373,11 @@ const PatchProjectDetails: Function = (url: string, projectData: any) => {
};
};

const PostFormUpdate: Function = (url: string, projectData: any) => {
const PostFormUpdate = (url: string, projectData: Record<string, any>) => {
return async (dispatch) => {
dispatch(CreateProjectActions.SetPostFormUpdateLoading(true));

const postFormUpdate = async (url, projectData) => {
const postFormUpdate = async (url: string, projectData: Record<string, any>) => {
try {
const formFormData = new FormData();
formFormData.append('xform_id', projectData.xformId);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/api/HomeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/api/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/frontend/src/api/OrganisationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>) {
for (const [key, value] of Object.entries(object)) {
// if (key === 'logo') {
// formData.append(key, value[0])
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 409007e

Please sign in to comment.