Skip to content

Commit

Permalink
feat: deprecate plantDate from PlantLocationBase type
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitb35 committed Oct 4, 2024
1 parent 5604885 commit bc8d1d1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/features/common/types/plantLocation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand Down
4 changes: 3 additions & 1 deletion src/features/projects/components/maps/PlantLocations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 9 additions & 7 deletions src/features/user/TreeMapper/Import/components/ReviewSubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
Expand Down
18 changes: 0 additions & 18 deletions src/features/user/TreeMapper/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions src/features/user/TreeMapper/components/PlantLocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down

0 comments on commit bc8d1d1

Please sign in to comment.