Skip to content

Commit

Permalink
fix: project edit form update validation (#1397)
Browse files Browse the repository at this point in the history
* feat formUpdateTab: form validation api add

* fix projectDetails: toggle debug console btn replaced with checkbox

* fix project: consoles remove
  • Loading branch information
NSUWAL123 authored Mar 29, 2024
1 parent 66d743a commit 949a789
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/api/CreateProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ const ValidateCustomForm: Function = (url: string, formUpload: any) => {
dispatch(
CommonActions.SetSnackBar({
open: true,
message: JSON.stringify(error.response.data.detail) || 'Something Went Wrong',
message: JSON.stringify(error) || 'Something Went Wrong',
variant: 'error',
duration: 5000,
}),
Expand Down
2 changes: 0 additions & 2 deletions src/frontend/src/api/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,9 @@ export const GenerateProjectTiles = (url, payload) => {
const generateProjectTiles = async (url, payload) => {
try {
const response = await CoreModules.axios.get(url);
console.log(response, 'response-mbtiles');
dispatch(GetTilesList(`${import.meta.env.VITE_API_URL}/projects/tiles_list/${payload}/`));
dispatch(ProjectActions.SetGenerateProjectTilesLoading(false));
} catch (error) {
console.log(error, 'error-mbtiles');
dispatch(ProjectActions.SetGenerateProjectTilesLoading(false));
} finally {
dispatch(ProjectActions.SetGenerateProjectTilesLoading(false));
Expand Down
4 changes: 0 additions & 4 deletions src/frontend/src/api/ProjectTaskStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ const UpdateTaskStatus = (url, style, existingData, currentProjectId, feature, m

const response = await CoreModules.axios.post(url, body, { params });
const findIndexForUpdation = existingData[index].taskBoundries.findIndex((obj) => obj.id == response.data.id);
console.log(response, 'response');

let project_tasks = [...existingData[index].taskBoundries];
project_tasks[findIndexForUpdation] = {
...response.data,
task_status: task_priority_str[response.data.task_status],
};
console.log(project_tasks, 'project_tasks');

let updatedProject = [...existingData];
const finalProjectOBJ = {
Expand All @@ -31,7 +29,6 @@ const UpdateTaskStatus = (url, style, existingData, currentProjectId, feature, m
updatedProject[index] = finalProjectOBJ;

dispatch(ProjectActions.SetProjectTaskBoundries(updatedProject));
console.log(updatedProject, 'updatedProject');

await feature.setStyle(style);
dispatch(CommonActions.SetLoading(false));
Expand All @@ -44,7 +41,6 @@ const UpdateTaskStatus = (url, style, existingData, currentProjectId, feature, m
}),
);
} catch (error) {
console.log(error, 'error');
dispatch(CommonActions.SetLoading(false));
dispatch(
HomeActions.SetSnackBar({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import UploadArea from '../../common/UploadArea';
import Button from '../../common/Button';
import { CustomSelect } from '@/components/common/Select';
import CoreModules from '@/shared/CoreModules';
import { FormCategoryService } from '@/api/CreateProjectService';
import { FormCategoryService, ValidateCustomForm } from '@/api/CreateProjectService';
import { PostFormUpdate } from '@/api/CreateProjectService';
import { CreateProjectActions } from '@/store/slices/CreateProjectSlice';
import { CommonActions } from '@/store/slices/CommonSlice';
import { Loader2 } from 'lucide-react';

type FileType = {
id: string;
Expand All @@ -20,8 +23,11 @@ const FormUpdateTab = ({ projectId }) => {
const [uploadForm, setUploadForm] = useState<FileType[] | null>(null);
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
const [error, setError] = useState({ formError: '', categoryError: '' });

const formCategoryList = useAppSelector((state) => state.createproject.formCategoryList);
const sortedFormCategoryList = formCategoryList.slice().sort((a, b) => a.title.localeCompare(b.title));
const customFileValidity = useAppSelector((state) => state.createproject.customFileValidity);
const validateCustomFormLoading = useAppSelector((state) => state.createproject.validateCustomFormLoading);

useEffect(() => {
dispatch(FormCategoryService(`${import.meta.env.VITE_API_URL}/central/list-forms`));
Expand All @@ -38,6 +44,17 @@ const FormUpdateTab = ({ projectId }) => {
setError((prev) => ({ ...prev, categoryError: 'Category is required.' }));
isValid = false;
}
if (!customFileValidity && uploadForm && uploadForm.length > 0) {
dispatch(
CommonActions.SetSnackBar({
open: true,
message: 'Your file is invalid',
variant: 'error',
duration: 2000,
}),
);
isValid = false;
}
return isValid;
};

Expand All @@ -52,6 +69,12 @@ const FormUpdateTab = ({ projectId }) => {
}
};

useEffect(() => {
if (uploadForm && uploadForm?.length > 0 && !customFileValidity) {
dispatch(ValidateCustomForm(`${import.meta.env.VITE_API_URL}/projects/validate-form`, uploadForm?.[0]?.url));
}
}, [uploadForm]);

return (
<div className="fmtm-flex fmtm-flex-col fmtm-gap-10">
<div className="">
Expand Down Expand Up @@ -89,10 +112,17 @@ const FormUpdateTab = ({ projectId }) => {
data={uploadForm || []}
filterKey="url"
onUploadFile={(updatedFiles) => {
dispatch(CreateProjectActions.SetCustomFileValidity(false));
setUploadForm(updatedFiles);
}}
acceptedInput=".xls, .xlsx, .xml"
/>
{validateCustomFormLoading && (
<div className="fmtm-flex fmtm-items-center fmtm-gap-2 fmtm-mt-2">
<Loader2 className="fmtm-h-4 fmtm-w-4 fmtm-animate-spin fmtm-text-primaryRed" />
<p className="fmtm-text-base">Validating form...</p>
</div>
)}
{error.formError && <p className="fmtm-text-primaryRed fmtm-text-base">{error.formError}</p>}
</div>
<div className="fmtm-flex fmtm-justify-center">
Expand Down
15 changes: 9 additions & 6 deletions src/frontend/src/views/ProjectDetailsV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { Geolocation } from '@/utilfunctions/Geolocation';
import Instructions from '@/components/ProjectDetailsV2/Instructions';
import { readFileFromOPFS } from '@/api/Files';
import DebugConsole from '@/utilities/DebugConsole';
import { CustomCheckbox } from '@/components/common/Checkbox';

const Home = () => {
const dispatch = CoreModules.useAppDispatch();
Expand Down Expand Up @@ -229,7 +230,6 @@ const Home = () => {
return;
}

console.log(projectOpfsBasemapPath);
const opfsPmtilesData = await readFileFromOPFS(projectOpfsBasemapPath);
setCustomBasemapData(opfsPmtilesData);
// setCustomBasemapData(projectOpfsBasemapPath);
Expand Down Expand Up @@ -380,11 +380,14 @@ const Home = () => {
}`}
>
{import.meta.env.MODE === 'development' && (
<div className="fmtm-absolute fmtm-top-16 fmtm-left-4 fmtm-z-50">
<Button
btnText="Toggle Console"
btnType="secondary"
onClick={() => setShowDebugConsole(!showDebugConsole)}
<div className="fmtm-block sm:fmtm-hidden fmtm-absolute fmtm-top-6 fmtm-left-16 fmtm-z-50">
<CustomCheckbox
label="Toggle-Console"
checked={showDebugConsole}
onCheckedChange={(status) => {
setShowDebugConsole(status);
}}
className="fmtm-text-black !fmtm-w-full"
/>
</div>
)}
Expand Down

0 comments on commit 949a789

Please sign in to comment.