Skip to content

Commit

Permalink
Fixes a few typos
Browse files Browse the repository at this point in the history
  • Loading branch information
thiessenp-cds committed Oct 21, 2024
1 parent 0f2df3f commit 322675c
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions lib/hooks/useFormDelayContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const calculateSubmitDelay = (delayFromFormData: number) => {
* @param currentGroup curent group/page Id
* @returns count of required questions on the current page/group
*/
const getNumberOfRequireQuestionsGroups = (form: FormProperties, currentGroup: string) => {
const getNumberOfRequiredQuestionsWithGroups = (form: FormProperties, currentGroup: string) => {
const groupIds = form?.groups?.[currentGroup].elements;
if (!groupIds) {
return 0;
Expand All @@ -61,28 +61,28 @@ const getNumberOfRequireQuestionsGroups = (form: FormProperties, currentGroup: s
.filter((element) => element.properties.validation?.required === true).length;
};

const getNumberOfRequireQuestionsWithoutGroups = (form: FormProperties) => {
const getNumberOfRequiredQuestionsWithoutGroups = (form: FormProperties) => {
return form.elements.filter((element) => element.properties.validation?.required === true).length;
};

const calculateDelayWithoutGroups = (form: FormProperties) => {
const delayFromFormData = getNumberOfRequireQuestionsWithoutGroups(form);
return calculateSubmitDelay(delayFromFormData);
};

const calculateDelayWithGroups = (form: FormProperties, formDelay: FormDelay) => {
const elapsedTime = Math.floor((Date.now() - formDelay.startTime) / 1000);
// Uses state to get requried questions (vs. a non group that can use the current form)
const delayFromFormData = formDelay.requiredQuestions - elapsedTime;
return calculateSubmitDelay(delayFromFormData);
};

const calculateDelayWithoutGroups = (form: FormProperties) => {
const delayFromFormData = getNumberOfRequiredQuestionsWithoutGroups(form);
return calculateSubmitDelay(delayFromFormData);
};

export const useFormDelay = () => {
const { formDelay, setFormDelay } = useContext(FormDelayContext);
return {
/**
* Used only for forms with groups. This sets an initial start time that is later used to get
* the time a user has spent on a form.
* Sets an initial start time that is later used to get the time a user has spent on a form.
* Used only for forms with groups.
* @param currentGroup group Id of the current page
* @param form current form
*/
Expand All @@ -93,23 +93,24 @@ export const useFormDelay = () => {
setFormDelay({ ...formDelay, startTime: Date.now() });
},
/**
* Used only for forms with groups. This will set the form delay based on the current group.
* Set the form delay based on the current group. Used only for forms with groups.
* @param currentGroup group Id of the current page
* @param form current form
*/
setFormDelayGroups: (form: FormProperties, currentGroup: string) => {
const requiredQuestions = getNumberOfRequireQuestionsGroups(form, currentGroup);
const requiredQuestions = getNumberOfRequiredQuestionsWithGroups(form, currentGroup);
setFormDelay({
...formDelay,
requiredQuestions: requiredQuestions && formDelay.requiredQuestions + requiredQuestions,
});
},
/**
* Gets the form delay based on the form type. For non group forms, the countdown (submit button)
* Gets the form delay based on the form type. For non group forms, the countdown (SubmitButton)
* starts immediately so the time a user spends on a form minus the required questions will be
* small. While a form with groups, the delay could be massive because branching logic enables
* much bigger forms. This is why for a group form the time spent on the form is subtracted from
* only the required questions along the pages path a user navigates - reducing the delay.
* small. While a form with groups, the countdown could be massive because branching logic
* enables much bigger forms. This is why for a group form the time spent on the form is
* subtracted from only the required questions along the pages path a user navigates; reducing
* the delay used in the countdown.
* @param form current form
* @returns delay in seconds
*/
Expand Down

0 comments on commit 322675c

Please sign in to comment.