Skip to content

Commit

Permalink
chore: Use test clock for the initial date in trial assigning
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Feb 19, 2025
1 parent 2f1f6bb commit a24d996
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
FormHelperText,
Switch,
} from '@mui/material';
import { DateTimePickerField } from 'tg.component/common/form/fields/DateTimePickerField';
import LoadingButton from 'tg.component/common/form/LoadingButton';

import { useBillingApiMutation } from 'tg.service/http/useQueryApi';
Expand All @@ -24,6 +23,8 @@ import { Validation } from 'tg.constants/GlobalValidationSchema';
import { PlanSelectorField } from '../../subscriptionPlans/components/planForm/fields/PlanSelectorField';
import { CloudPlanFormData } from '../../subscriptionPlans/components/planForm/CloudPlanFormBase';
import { useTestClock } from 'tg.service/useTestClock';
import { AssignTrialDatePicker } from './AssignTrialDatePicker';
import { useCurrentDate } from 'tg.hooks/useCurrentDate';

export const AssignCloudTrialDialog: FC<{
open: boolean;
Expand Down Expand Up @@ -89,6 +90,8 @@ export const AssignCloudTrialDialog: FC<{
});
}

const currentDate = useCurrentDate();

return (
<Formik
initialValues={
Expand All @@ -102,7 +105,7 @@ export const AssignCloudTrialDialog: FC<{
validationSchema={Yup.object().shape({
trialEnd: Yup.date()
.required()
.min(new Date(), t('date-must-be-in-future-error-message')),
.min(currentDate, t('date-must-be-in-future-error-message')),
planId: Yup.number().required(),
customPlan: Validation.CLOUD_PLAN_FORM,
})}
Expand All @@ -114,19 +117,7 @@ export const AssignCloudTrialDialog: FC<{
<T keyName="administration-subscription-assign-trial-dialog-title" />
</DialogTitle>
<DialogContent sx={{ display: 'grid', gap: '16px' }}>
<DateTimePickerField
formControlProps={{
'data-cy': 'administration-trial-end-date-field',
sx: { mt: 1 },
}}
dateTimePickerProps={{
disablePast: true,
label: (
<T keyName="administration-subscription-assign-trial-end-date-field" />
),
}}
name="trialEnd"
/>
<AssignTrialDatePicker />
<FormHelperText>
<T keyName="administration-subscription-assign-trial-plan-help" />
</FormHelperText>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { T } from '@tolgee/react';
import { DateTimePickerField } from 'tg.component/common/form/fields/DateTimePickerField';
import React from 'react';

export const AssignTrialDatePicker = () => {
return (
<DateTimePickerField
formControlProps={{
'data-cy': 'administration-trial-end-date-field',
sx: { mt: 1 },
}}
dateTimePickerProps={{
disablePast: true,
label: (
<T keyName="administration-subscription-assign-trial-end-date-field" />
),
}}
name="trialEnd"
/>
);
};
11 changes: 11 additions & 0 deletions webapp/src/hooks/useCurrentDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useTestClock } from 'tg.service/useTestClock';

export const useCurrentDate = () => {
const testClock = useTestClock();

if (!testClock) {
return new Date();
}

return new Date(testClock);
};

0 comments on commit a24d996

Please sign in to comment.