Skip to content

Commit

Permalink
Add project start date as start date in ary dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
puranban committed Feb 29, 2024
1 parent a24bb25 commit cbd4d9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/gqlFragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export const LAST_ACTIVE_PROJECT_FRAGMENT = gql`
membershipPending
enablePubliclyViewableAnalysisReportSnapshot
isRejected
createdAt
}
`;

Expand Down
23 changes: 8 additions & 15 deletions app/views/AryDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import {
import { gql, useQuery } from '@apollo/client';
import { removeNull } from '@togglecorp/toggle-form';

import {
todaysDate,
lastYearStartDate,
DEEP_START_DATE,
} from '#utils/common';
import { todaysDate } from '#utils/common';
import { resolveTime } from '#utils/temporal';
import ProjectContext from '#base/context/ProjectContext';
import {
Expand Down Expand Up @@ -199,10 +195,15 @@ function AryDashboard(props: Props) {
const [selectedRegion, setSelectedRegion] = useState<string>();
const [activeAdminLevel, setActiveAdminLevel] = useState<string>();

const projectStartDate = resolveTime(
project?.createdAt ? new Date(project?.createdAt) : todaysDateTime,
'day',
).getTime();

const [
startDate = todaysDateTime,
startDate = projectStartDate,
setStartDate,
] = useState<number | undefined>(todaysDateTime);
] = useState<number | undefined>(projectStartDate);
const [
endDate = todaysDateTime,
setEndDate,
Expand Down Expand Up @@ -234,11 +235,6 @@ function AryDashboard(props: Props) {
skip: !activeProject,
variables: activeProject ? { projectId: activeProject } : undefined,
onCompleted: (response) => {
const projectStartDate = resolveTime(
new Date(response.project?.createdAt ?? todaysDateTime),
'day',
).getTime();
setStartDate(Math.max(projectStartDate, new Date(lastYearStartDate).getTime()));
setSelectedRegion(response.project?.regions?.[0].id);

if (isDefined(activeAdminLevel)) {
Expand Down Expand Up @@ -293,9 +289,6 @@ function AryDashboard(props: Props) {
}, [projectMetadata]);

const projectData = removeNull(data?.project);
const projectStartDate = useMemo(() => (
resolveTime(new Date(projectMetadata?.createdAt ?? DEEP_START_DATE), 'day').getTime()
), [projectMetadata?.createdAt]);

const handleEndDateChange = useCallback((newDate: number | undefined) => {
if (isDefined(newDate)) {
Expand Down

0 comments on commit cbd4d9e

Please sign in to comment.