Skip to content

Commit 825b92d

Browse files
committed
refactor(dashboard): include today's feedback in feedback overview
1 parent 0a2186b commit 825b92d

File tree

8 files changed

+13
-40
lines changed

8 files changed

+13
-40
lines changed

src/app/page.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ const HomePage = async () => {
4949
isMember: true,
5050
};
5151

52-
const oneWeekAgo = dayjs().utc().subtract(7, "days").startOf("day").toDate();
53-
const startOfToday = dayjs().utc().startOf("day").toDate();
52+
const oneWeekAgo = dayjs().utc().subtract(6, "days").startOf("day").toDate();
5453

5554
await Promise.all([
5655
queryClient.prefetchQuery({
@@ -81,12 +80,10 @@ const HomePage = async () => {
8180
queryKey: useWeeklyFeedbackQuery.getKey({
8281
userId: session.user.rowId!,
8382
startDate: oneWeekAgo,
84-
endDate: startOfToday,
8583
}),
8684
queryFn: useWeeklyFeedbackQuery.fetcher({
8785
userId: session.user.rowId!,
8886
startDate: oneWeekAgo,
89-
endDate: startOfToday,
9087
}),
9188
}),
9289
queryClient.prefetchQuery({
@@ -101,7 +98,6 @@ const HomePage = async () => {
10198
isBasicTier={isBasicTier}
10299
isTeamTier={isTeamTier}
103100
oneWeekAgo={oneWeekAgo}
104-
startOfToday={startOfToday}
105101
/>
106102

107103
{/* dialogs */}

src/components/dashboard/DashboardPage/DashboardPage.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,12 @@ interface Props {
3030
isTeamTier: boolean;
3131
/** Start of day from one week ago. */
3232
oneWeekAgo: Date;
33-
/** Start of today. */
34-
startOfToday: Date;
3533
}
3634

3735
/**
3836
* Dashboard page. This provides the main layout for the home page when the user is authenticated.
3937
*/
40-
const DashboardPage = ({
41-
isBasicTier,
42-
isTeamTier,
43-
oneWeekAgo,
44-
startOfToday,
45-
}: Props) => {
38+
const DashboardPage = ({ isBasicTier, isTeamTier, oneWeekAgo }: Props) => {
4639
const { user, isLoading: isAuthLoading } = useAuth();
4740

4841
const {
@@ -122,7 +115,7 @@ const DashboardPage = ({
122115
</Grid>
123116

124117
<Grid h="100%" w="100%" gap={6} columns={{ base: 1, md: 2 }}>
125-
<FeedbackOverview oneWeekAgo={oneWeekAgo} startOfToday={startOfToday} />
118+
<FeedbackOverview oneWeekAgo={oneWeekAgo} />
126119

127120
<RecentFeedback />
128121
</Grid>

src/components/dashboard/FeedbackOverview/FeedbackOverview.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ import { useAuth, useViewportSize } from "lib/hooks";
2121
interface Props {
2222
/** Start of day from one week ago. */
2323
oneWeekAgo: Date;
24-
/** Start of today. */
25-
startOfToday: Date;
2624
}
2725

2826
/**
2927
* Feedback overview section. Displays a bar chart that displays daily feedback volume for the past 7 days.
3028
*/
31-
const FeedbackOverview = ({ oneWeekAgo, startOfToday }: Props) => {
29+
const FeedbackOverview = ({ oneWeekAgo }: Props) => {
3230
const isLargeViewport = useViewportSize({ minWidth: "64em" });
3331

3432
const getFormattedDate = (diff: number) =>
@@ -44,7 +42,6 @@ const FeedbackOverview = ({ oneWeekAgo, startOfToday }: Props) => {
4442
{
4543
userId: user?.rowId!,
4644
startDate: oneWeekAgo,
47-
endDate: startOfToday,
4845
},
4946
{
5047
enabled: !!user?.rowId,
@@ -80,7 +77,7 @@ const FeedbackOverview = ({ oneWeekAgo, startOfToday }: Props) => {
8077
contentProps={{
8178
align: "center",
8279
justify: "center",
83-
p: 4,
80+
p: 2,
8481
}}
8582
>
8683
{!isLoading ? (

src/components/dashboard/Response/Response.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ interface Props extends FlexProps {
2222
* Recent feedback response.
2323
*/
2424
const Response = ({ feedback, ...rest }: Props) => {
25-
const startOfDay = dayjs(feedback?.createdAt).utc().startOf("day");
26-
27-
const isToday = dayjs.duration(dayjs().utc().diff(startOfDay)).asDays() < 1;
28-
29-
// NB: `isToday` is used to stabilize the relative time in order to keep in sync with `FeedbackOverview` calculations.
30-
const date = isToday
31-
? dayjs(feedback?.createdAt).utc().fromNow()
32-
: startOfDay.fromNow();
25+
const date = dayjs(feedback?.createdAt).utc().fromNow();
3326

3427
return (
3528
<Stack gap={4} w="100%" {...rest}>

src/generated/graphql.mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ export const mockUserByEmailQuery = (resolver: GraphQLResponseResolver<Types.Use
10221022
* @example
10231023
* mockWeeklyFeedbackQuery(
10241024
* ({ query, variables }) => {
1025-
* const { userId, startDate, endDate } = variables;
1025+
* const { userId, startDate } = variables;
10261026
* return HttpResponse.json({
10271027
* data: { posts }
10281028
* })

src/generated/graphql.sdk.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5286,7 +5286,6 @@ export type UserByEmailQuery = { __typename?: 'Query', userByEmail?: { __typenam
52865286
export type WeeklyFeedbackQueryVariables = Exact<{
52875287
userId: Scalars['UUID']['input'];
52885288
startDate: Scalars['Datetime']['input'];
5289-
endDate: Scalars['Datetime']['input'];
52905289
}>;
52915290

52925291

@@ -5916,9 +5915,9 @@ export const UserByEmailDocument = gql`
59165915
}
59175916
`;
59185917
export const WeeklyFeedbackDocument = gql`
5919-
query WeeklyFeedback($userId: UUID!, $startDate: Datetime!, $endDate: Datetime!) {
5918+
query WeeklyFeedback($userId: UUID!, $startDate: Datetime!) {
59205919
posts(
5921-
filter: {project: {organization: {members: {some: {userId: {equalTo: $userId}}}}}, createdAt: {greaterThanOrEqualTo: $startDate, lessThan: $endDate}}
5920+
filter: {project: {organization: {members: {some: {userId: {equalTo: $userId}}}}}, createdAt: {greaterThanOrEqualTo: $startDate}}
59225921
) {
59235922
groupedAggregates(groupBy: [CREATED_AT_TRUNCATED_TO_DAY]) {
59245923
keys

src/generated/graphql.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5285,7 +5285,6 @@ export type UserByEmailQuery = { __typename?: 'Query', userByEmail?: { __typenam
52855285
export type WeeklyFeedbackQueryVariables = Exact<{
52865286
userId: Scalars['UUID']['input'];
52875287
startDate: Scalars['Datetime']['input'];
5288-
endDate: Scalars['Datetime']['input'];
52895288
}>;
52905289

52915290

@@ -7294,9 +7293,9 @@ useInfiniteUserByEmailQuery.getKey = (variables: UserByEmailQueryVariables) => [
72947293
useUserByEmailQuery.fetcher = (variables: UserByEmailQueryVariables, options?: RequestInit['headers']) => graphqlFetch<UserByEmailQuery, UserByEmailQueryVariables>(UserByEmailDocument, variables, options);
72957294

72967295
export const WeeklyFeedbackDocument = `
7297-
query WeeklyFeedback($userId: UUID!, $startDate: Datetime!, $endDate: Datetime!) {
7296+
query WeeklyFeedback($userId: UUID!, $startDate: Datetime!) {
72987297
posts(
7299-
filter: {project: {organization: {members: {some: {userId: {equalTo: $userId}}}}}, createdAt: {greaterThanOrEqualTo: $startDate, lessThan: $endDate}}
7298+
filter: {project: {organization: {members: {some: {userId: {equalTo: $userId}}}}}, createdAt: {greaterThanOrEqualTo: $startDate}}
73007299
) {
73017300
groupedAggregates(groupBy: [CREATED_AT_TRUNCATED_TO_DAY]) {
73027301
keys

src/lib/graphql/queries/weeklyFeedback.query.graphql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
query WeeklyFeedback(
2-
$userId: UUID!
3-
$startDate: Datetime!
4-
$endDate: Datetime!
5-
) {
1+
query WeeklyFeedback($userId: UUID!, $startDate: Datetime!) {
62
posts(
73
filter: {
84
project: {
95
organization: { members: { some: { userId: { equalTo: $userId } } } }
106
}
11-
createdAt: { greaterThanOrEqualTo: $startDate, lessThan: $endDate }
7+
createdAt: { greaterThanOrEqualTo: $startDate }
128
}
139
) {
1410
groupedAggregates(groupBy: [CREATED_AT_TRUNCATED_TO_DAY]) {

0 commit comments

Comments
 (0)