Skip to content

Commit

Permalink
fix: New plan with key and seat metric creation and test
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Mar 4, 2025
1 parent 5ecb737 commit 848b73f
Show file tree
Hide file tree
Showing 11 changed files with 886 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ enum class Message {
CANNOT_UPDATE_WITHOUT_MODIFICATION,
CURRENT_SUBSCRIPTION_IS_NOT_TRIALING,
SORTING_AND_PAGING_IS_NOT_SUPPORTED_WHEN_USING_CURSOR,
STRINGS_METRIC_ARE_NOT_SUPPORTED,
;

val code: String
Expand Down
5 changes: 4 additions & 1 deletion e2e/cypress/support/dataCyType.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ declare namespace DataCy {
"administration-billing-edit-custom-plan-button" |
"administration-billing-exclusive-plan-chip" |
"administration-billing-trial-badge" |
"administration-cloud-plan-field-feature" |
"administration-cloud-plan-field-free" |
"administration-cloud-plan-field-included-keys" |
"administration-cloud-plan-field-included-mt-credits" |
"administration-cloud-plan-field-included-seats" |
"administration-cloud-plan-field-included-translations" |
"administration-cloud-plan-field-metric-type" |
"administration-cloud-plan-field-metric-type-item" |
"administration-cloud-plan-field-name" |
"administration-cloud-plan-field-price-monthly" |
"administration-cloud-plan-field-price-per-seat" |
Expand Down Expand Up @@ -72,6 +74,7 @@ declare namespace DataCy {
"administration-organizations-list-item" |
"administration-organizations-projects-button" |
"administration-organizations-settings-button" |
"administration-plan-field-feature" |
"administration-plan-field-non-commercial" |
"administration-plan-selector" |
"administration-subscriptions-cloud-plan-name" |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ type CloudPlanModel = components['schemas']['CloudPlanRequest'];
type EnabledFeature =
components['schemas']['CloudPlanRequest']['enabledFeatures'][number];

export type MetricType = 'STRINGS' | 'SEATS_KEYS';
export type MetricType =
components['schemas']['CloudPlanRequest']['metricType'];

export type CloudPlanFormData = {
type: CloudPlanModel['type'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { TextField } from 'tg.component/common/form/fields/TextField';
import { useTranslate } from '@tolgee/react';
import {
Box,
Checkbox,
FormControlLabel,
Switch,
Typography,
} from '@mui/material';
import { Field, FieldProps, useFormikContext } from 'formik';
import { useBillingApiQuery } from 'tg.service/http/useQueryApi';
import { Box, FormControlLabel, Switch } from '@mui/material';
import { useFormikContext } from 'formik';
import React, { FC } from 'react';
import { CloudPlanPricesAndLimits } from './CloudPlanPricesAndLimits';
import { PlanNonCommercialSwitch } from './PlanNonCommercialSwitch';
import { useCloudPlanFormValues } from '../useCloudPlanFormValues';
import { CloudPlanTypeSelectField } from './CloudPlanTypeSelectField';
import { StripeProductSelectField } from './StripeProductSelectField';
import { PlanStripeProductSelectField } from './PlanStripeProductSelectField';
import { CloudPlanMetricTypeSelectField } from './CloudPlanMetricTypeSelectField';
import { PlanEnabledFeaturesField } from './PlanEnabledFeaturesField';

Expand All @@ -25,7 +18,7 @@ export const CloudPlanFields: FC<{
}> = ({ parentName, isUpdate, canEditPrices }) => {
const { t } = useTranslate();

const { setFieldValue } = useFormikContext<any>();
const { setFieldValue, errors } = useFormikContext<any>();

const { values } = useCloudPlanFormValues(parentName);

Expand All @@ -35,6 +28,8 @@ export const CloudPlanFields: FC<{
setFieldValue(`${parentName}free`, !values.free);
}

console.log({ errors, values });

return (
<>
<TextField
Expand Down Expand Up @@ -62,7 +57,7 @@ export const CloudPlanFields: FC<{
>
<CloudPlanTypeSelectField parentName={parentName} />
<CloudPlanMetricTypeSelectField parentName={parentName} />
<StripeProductSelectField />
<PlanStripeProductSelectField parentName={parentName} />
</Box>

<CloudPlanPricesAndLimits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const CloudPlanIncludedUsage: FC<CloudPlanPricesProps> = ({
</Typography>
<Box
display="grid"
gridTemplateColumns="repeat(4, 1fr)"
gridTemplateColumns="repeat(3, 1fr)"
gap={2}
sx={{ mt: 1 }}
>
Expand Down Expand Up @@ -52,9 +52,8 @@ export const CloudPlanIncludedUsage: FC<CloudPlanPricesProps> = ({
/>
)}

{values.metricType == 'SEATS_KEYS' && (
{values.metricType == 'KEYS_SEATS' && (
<>
{/*TODO: Test that for fixed plan we cannot set the prices in the backend tests */}
<TextField
name={`${parentName}includedUsage.keys`}
size="small"
Expand All @@ -68,7 +67,7 @@ export const CloudPlanIncludedUsage: FC<CloudPlanPricesProps> = ({
size="small"
type="number"
fullWidth
data-cy="administration-cloud-plan-field-included-keys"
data-cy="administration-cloud-plan-field-included-seats"
label={t('administration_cloud_plan_field_included_seats')}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useEffect } from 'react';
import React, { FC } from 'react';
import { Select } from 'tg.component/common/form/fields/Select';
import { MenuItem } from '@mui/material';
import { useTranslate } from '@tolgee/react';
Expand All @@ -17,9 +17,9 @@ export const CloudPlanMetricTypeSelectField: FC<
const { values } = useCloudPlanFormValues(parentName);

const options = [
{ value: 'SEATS_KEYS', label: 'Keys & Seats' },
{ value: 'KEYS_SEATS', label: 'Keys & Seats' },
{ value: 'STRINGS', label: 'Strings' },
] as { value: MetricType; label: string }[];
] satisfies { value: MetricType; label: string }[];

if (values.type == 'SLOTS_FIXED') {
return null;
Expand All @@ -33,14 +33,14 @@ export const CloudPlanMetricTypeSelectField: FC<
fullWidth
minHeight={false}
sx={{ flexBasis: '50%' }}
data-cy="administration-cloud-plan-field-type"
data-cy="administration-cloud-plan-field-metric-type"
renderValue={(val) => options.find((o) => o.value === val)?.label}
>
{options.map(({ value, label }) => (
<MenuItem
key={value}
value={value}
data-cy="administration-cloud-plan-field-type-item"
data-cy="administration-cloud-plan-field-metric-type-item"
>
{label}
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ export const CloudPlanPrices: FC<CloudPlanPricesProps> = ({ parentName }) => {

return (
<>
<Typography sx={{ mt: 2 }}>
<Typography sx={{ mt: 4 }} variant="h3">
{t('administration_cloud_plan_form_prices_title')}
</Typography>
<Typography>
{t('administration_cloud_plan_form_prices_per_subscription')}
</Typography>
<Box
display="grid"
gridTemplateColumns="repeat(4, 1fr)"
gridTemplateColumns="repeat(2, 1fr)"
gap={2}
sx={{ mt: 1 }}
>
Expand All @@ -80,6 +83,18 @@ export const CloudPlanPrices: FC<CloudPlanPricesProps> = ({ parentName }) => {
type="number"
fullWidth
/>
</Box>

<Typography>
{t('administration_cloud_plan_form_prices_per_usage')}
</Typography>

<Box
display="grid"
gridTemplateColumns="repeat(3, 1fr)"
gap={2}
sx={{ mt: 1 }}
>
<TextField
name={`${parentName}prices.perThousandMtCredits`}
size="small"
Expand All @@ -91,7 +106,6 @@ export const CloudPlanPrices: FC<CloudPlanPricesProps> = ({ parentName }) => {
fullWidth
disabled={type !== 'PAY_AS_YOU_GO'}
/>
{/*TODO: Split usage based and subscription based prices*/}
{metricType == 'STRINGS' && (
<>
<TextField
Expand All @@ -107,7 +121,7 @@ export const CloudPlanPrices: FC<CloudPlanPricesProps> = ({ parentName }) => {
/>
</>
)}
{metricType == 'SEATS_KEYS' && (
{metricType == 'KEYS_SEATS' && (
<>
<TextField
name={`${parentName}prices.perThousandKeys`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const PlanEnabledFeaturesField: FC<EnabledFeaturesFieldProps> = ({

return (
<FormControlLabel
data-cy="administration-cloud-plan-field-feature"
data-cy="administration-plan-field-feature"
key={feature}
control={
<Checkbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ type StripeProductSelectFieldProps = {
parentName?: string;
};

export const StripeProductSelectField: FC<StripeProductSelectFieldProps> = ({
parentName,
}) => {
export const PlanStripeProductSelectField: FC<
StripeProductSelectFieldProps
> = ({ parentName }) => {
const productsLoadable = useBillingApiQuery({
url: '/v2/administration/billing/stripe-products',
method: 'get',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ export const getCloudPlanInitialValues = (
? planData.includedUsage.translationSlots
: planData.includedUsage.translations,
},
metricType: planData.includedUsage.keys > 0 ? 'SEATS_KEYS' : 'STRINGS',
} as CloudPlanFormData;
}

return {
type: 'PAY_AS_YOU_GO',
metricType: 'SEATS_KEYS',
metricType: 'KEYS_SEATS',
name: '',
stripeProductId: '',
prices: {
Expand Down
Loading

0 comments on commit 848b73f

Please sign in to comment.