From 5604885088dca55df7fce3ac23e4ae91e401e3f2 Mon Sep 17 00:00:00 2001
From: mohitb35 <44917347+mohitb35@users.noreply.github.com>
Date: Fri, 4 Oct 2024 12:40:20 +0530
Subject: [PATCH 1/2] feat: adapt dataExplorer export for
 intervention_start_date

---
 public/static/locales/en/treemapperAnalytics.json           | 2 +-
 src/features/common/types/dataExplorer.d.ts                 | 2 +-
 .../user/TreeMapper/Analytics/components/Export/index.tsx   | 6 ++++--
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/public/static/locales/en/treemapperAnalytics.json b/public/static/locales/en/treemapperAnalytics.json
index 8d7d41d9ea..bb2d5abd10 100644
--- a/public/static/locales/en/treemapperAnalytics.json
+++ b/public/static/locales/en/treemapperAnalytics.json
@@ -28,7 +28,7 @@
     "dec": "Dec",
     "exportColumnHeaders": {
       "hid": "Human Readable ID for a plant location",
-      "plantDate": "Planted Date",
+      "interventionStartDate": "Starting date of intervention (e.g. Tree planting date)",
       "species": "Name of the species planted",
       "treeCount": "",
       "geometry": "GeoJson Co-ordinate of the polygon",
diff --git a/src/features/common/types/dataExplorer.d.ts b/src/features/common/types/dataExplorer.d.ts
index f0e18e9240..96c914f24c 100644
--- a/src/features/common/types/dataExplorer.d.ts
+++ b/src/features/common/types/dataExplorer.d.ts
@@ -34,7 +34,7 @@ export interface ISpeciesPlanted {
 
 export interface IExportData {
   hid: string;
-  plant_date: Date;
+  intervention_start_date: Date;
   species: string;
   tree_count: number;
   geometry: string;
diff --git a/src/features/user/TreeMapper/Analytics/components/Export/index.tsx b/src/features/user/TreeMapper/Analytics/components/Export/index.tsx
index 2d26301cfb..70d5667a95 100644
--- a/src/features/user/TreeMapper/Analytics/components/Export/index.tsx
+++ b/src/features/user/TreeMapper/Analytics/components/Export/index.tsx
@@ -78,8 +78,8 @@ export const Export = () => {
       description: t('exportColumnHeaders.hid'),
     },
     {
-      title: 'plant_date',
-      description: t('exportColumnHeaders.plantDate'),
+      title: 'intervention_start_date',
+      description: t('exportColumnHeaders.interventionStartDate'),
     },
     {
       title: 'species',
@@ -142,6 +142,7 @@ export const Export = () => {
   };
 
   const extractDataToXlsx = (data: IExportData[]) => {
+    console.log('Data for export:', data[0]);
     const worksheet = utils.json_to_sheet(data);
     const workbook = utils.book_new();
 
@@ -173,6 +174,7 @@ export const Export = () => {
   const handleExport = async () => {
     if (localProject) {
       const res = await makeRequest();
+      console.log('Data received from API:', res?.data[0]);
 
       if (res) {
         const { data } = res;

From bc8d1d1781ddc14b6e1bc48b2f8058563b449449 Mon Sep 17 00:00:00 2001
From: mohitb35 <44917347+mohitb35@users.noreply.github.com>
Date: Fri, 4 Oct 2024 15:15:57 +0530
Subject: [PATCH 2/2] feat: deprecate plantDate from `PlantLocationBase` type

---
 src/features/common/types/plantLocation.d.ts   |  1 -
 .../PlantLocation/PlantLocationDetails.tsx     |  4 +++-
 .../components/maps/PlantLocations.tsx         |  4 +++-
 .../Import/components/ReviewSubmit.tsx         | 16 +++++++++-------
 .../user/TreeMapper/components/Map.tsx         | 18 ------------------
 .../components/PlantLocationPage.tsx           | 12 ++++++++----
 6 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/src/features/common/types/plantLocation.d.ts b/src/features/common/types/plantLocation.d.ts
index 529b50d57b..b82693b0c0 100644
--- a/src/features/common/types/plantLocation.d.ts
+++ b/src/features/common/types/plantLocation.d.ts
@@ -11,7 +11,6 @@ export interface PlantLocationBase {
   registrationDate: DateString;
   /** @deprecated */
   plantDate: DateString;
-  interventionDate: DateString;
   interventionStartDate: DateString | null; //should be the same as interventionDate
   interventionEndDate: DateString | null;
   lastMeasurementDate: DateString | null;
diff --git a/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx b/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx
index dd781f6e19..0c2a2773c2 100644
--- a/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx
+++ b/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx
@@ -207,7 +207,9 @@ export default function PlantLocationDetails({
               <div className={styles.singleDetail}>
                 <div className={styles.detailTitle}>{t('plantingDate')}</div>
                 <div className={styles.detailValue}>
-                  {formatDate(plantLocation.plantDate)}
+                  {plantLocation.interventionStartDate
+                    ? formatDate(plantLocation.interventionStartDate)
+                    : '-'}
                 </div>
               </div>
               {(plantLocation.type === 'sample-tree-registration' ||
diff --git a/src/features/projects/components/maps/PlantLocations.tsx b/src/features/projects/components/maps/PlantLocations.tsx
index 839eb06783..79aa9e1aff 100644
--- a/src/features/projects/components/maps/PlantLocations.tsx
+++ b/src/features/projects/components/maps/PlantLocations.tsx
@@ -98,8 +98,10 @@ export default function PlantLocations(): ReactElement {
   };
 
   const getDateDiff = (pl: PlantLocation) => {
+    if (!pl.interventionStartDate) return null;
+
     const today = new Date();
-    const plantationDate = new Date(pl.plantDate?.substr(0, 10));
+    const plantationDate = new Date(pl.interventionStartDate?.slice(0, 10));
     const differenceInTime = today.getTime() - plantationDate.getTime();
     const differenceInDays = differenceInTime / (1000 * 3600 * 24);
     if (differenceInDays < 1) {
diff --git a/src/features/user/TreeMapper/Import/components/ReviewSubmit.tsx b/src/features/user/TreeMapper/Import/components/ReviewSubmit.tsx
index faf556a09f..75b409e6c7 100644
--- a/src/features/user/TreeMapper/Import/components/ReviewSubmit.tsx
+++ b/src/features/user/TreeMapper/Import/components/ReviewSubmit.tsx
@@ -60,14 +60,16 @@ export default function ReviewSubmit({
                     {plantLocation.captureMode}
                   </div>
                 </div>
-                <div className={styles.gridItem}>
-                  <div className={styles.gridItemTitle}>
-                    {tTreemapper('plantDate')}
+                {plantLocation.interventionStartDate !== null && (
+                  <div className={styles.gridItem}>
+                    <div className={styles.gridItemTitle}>
+                      {tTreemapper('plantDate')}
+                    </div>
+                    <div className={styles.gridItemValue}>
+                      {formatDate(plantLocation.interventionStartDate)}
+                    </div>
                   </div>
-                  <div className={styles.gridItemValue}>
-                    {formatDate(plantLocation.plantDate)}
-                  </div>
-                </div>
+                )}
                 <div className={styles.gridItem}>
                   <div className={styles.gridItemTitle}>
                     {tTreemapper('registrationDate')}
diff --git a/src/features/user/TreeMapper/components/Map.tsx b/src/features/user/TreeMapper/components/Map.tsx
index 80923e7999..2fb213e662 100644
--- a/src/features/user/TreeMapper/components/Map.tsx
+++ b/src/features/user/TreeMapper/components/Map.tsx
@@ -108,24 +108,6 @@ export default function MyTreesMap({
     }
   };
 
-  // const getDateDiff = (pl: PlantLocation) => {
-  //   const today = new Date();
-  //   const plantationDate = new Date(pl.plantDate?.substr(0, 10));
-  //   const differenceInTime = today.getTime() - plantationDate.getTime();
-  //   const differenceInDays = differenceInTime / (1000 * 3600 * 24);
-  //   if (differenceInDays < 1) {
-  //     return t('today');
-  //   } else if (differenceInDays < 2) {
-  //     return t('yesterday');
-  //   } else if (differenceInDays < 30) {
-  //     return t('daysAgo', {
-  //       days: localizedAbbreviatedNumber(i18n.language, differenceInDays, 0),
-  //     });
-  //   } else {
-  //     return null;
-  //   }
-  // };
-
   const zoomToLocation = (geometry: turf.AllGeoJSON) => {
     if (viewport.width && viewport.height && geometry) {
       const bbox = turf.bbox(geometry);
diff --git a/src/features/user/TreeMapper/components/PlantLocationPage.tsx b/src/features/user/TreeMapper/components/PlantLocationPage.tsx
index 3046773f7d..95321d8c87 100644
--- a/src/features/user/TreeMapper/components/PlantLocationPage.tsx
+++ b/src/features/user/TreeMapper/components/PlantLocationPage.tsx
@@ -153,10 +153,14 @@ export function LocationDetails({
         ) : (
           []
         )}
-        <div className={styles.singleDetail}>
-          <p className={styles.title}>{tTreemapper('plantDate')}</p>
-          <div className={styles.value}>{formatDate(location.plantDate)}</div>
-        </div>
+        {location.interventionStartDate !== null && (
+          <div className={styles.singleDetail}>
+            <p className={styles.title}>{tTreemapper('plantDate')}</p>
+            <div className={styles.value}>
+              {formatDate(location.interventionStartDate)}
+            </div>
+          </div>
+        )}
         <div className={styles.singleDetail}>
           <p className={styles.title}>{tTreemapper('registrationDate')}</p>
           <div className={styles.value}>