Skip to content

Add submitMetrics hook#362

Open
idke64 wants to merge 3 commits intobog-f25-sprint2from
andy/355-submitMetrics-hook
Open

Add submitMetrics hook#362
idke64 wants to merge 3 commits intobog-f25-sprint2from
andy/355-submitMetrics-hook

Conversation

@idke64
Copy link
Contributor

@idke64 idke64 commented Sep 27, 2025

Summary

Resolves #355

Adds submitMetrics hook, validation logic, and a sandbox page #/sandbox/submitMetrics to test the hook. submitMetrics calls the firebase cloud function submitMetrics and retries up to 3 times using exponential backoff.

The sandbox page is located in /src/sandbox/submitMetrics and its route is set up in the router component. These should not go into production.

Checklist

  • Create a useSubmitMetrics hook in src/data/hooks that given a metrics type (that you will define similar to the previous ticket) will call the firebase function you just made.
  • You will need to validate the data you send in the hook. Make utility functions for this.
  • Create a testing page /sandbox/submitMetrics with a sample form that lets you submit metrics using the hook. This should only be available on a dev environment not a prod environment. We will delete this later as it is just for testing, so do not worry about styling at all.
  • While fetching the data, if there is an error, retry a maximum of three times.

How to Test

Testing can be done by going to #/sandbox/submitMetrics. The user must be authenticated and the firebase endpoint must have the submitMetrics function for the entire process to work. However, testing for errors (invalid data, unauthenticated user) can be done completely locally.

20250927_15h38m29s_grim

@idke64 idke64 requested a review from uma-anand September 27, 2025 19:45
@github-actions
Copy link

github-actions bot commented Sep 27, 2025

PR Preview Action v1.6.2

🚀 View preview at
https://gt-scheduler.github.io/website/pr-preview/pr-362/

Built to branch gh-pages at 2025-09-28 17:32 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@uma-anand uma-anand changed the base branch from main to bog-f25-sprint2 September 28, 2025 00:53
@uma-anand
Copy link
Member

Adding a screenshot of a test metric created for joy and whimsy
image

Copy link
Member

@uma-anand uma-anand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of changes. Think something happened with git. Try to merge with main and resubmit. Most comments mimic those in the other PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calendar changes seem to come from your previous ticket- probably due to an early fork. Can you discard all non-ticket related changes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comment on calendar changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove it from here during the final commit btw. This was mainly to test + a useful reference for whoever does the frontend later on how the hook works.

IDToken: await auth.currentUser?.getIdToken(),
...requestData,
});
/* eslint-disable max-len */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not to disable the linter. If the line's too long (doesn't really look like it is), just break it up

return state;
}

function validateMetricData(data: unknown): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make these utils in another file pretty much identical to the cloud function. Also apply the fixes (in professor validation etc.) mentioned there here.

}
>;

export interface MetricTarget {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add types pretty much identical to the ones in firebase-conf, you can just copy-paste

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not gonna comment on this as its temporary. Add a comment saying to delete later.

const submitOperation = new Cancellable();

async function submit(): Promise<void> {
setState({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all these set states try to use the original state definition wherever possible so its clear. Mark the types as they are defined like LoadingStateLoaded<string>

@idke64 idke64 force-pushed the andy/355-submitMetrics-hook branch from c0c59b1 to da121a9 Compare September 28, 2025 17:26
Copy link
Member

@uma-anand uma-anand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! TYSM. Will merge in after firebase-conf is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BoG F25] Add useSubmitMetrics hook

2 participants