Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: launch us region #5962

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import * as styles from './index.module.scss';
type Props = {
readonly plan: SubscriptionPlan;
readonly onSelect: () => void;
readonly buttonProps?: Partial<React.ComponentProps<typeof Button>>;
};

function PlanCardItem({ plan, onSelect }: Props) {
function PlanCardItem({ plan, onSelect, buttonProps }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.upsell.create_tenant' });
const { tenants } = useContext(TenantsContext);
const { stripeProducts, id: planId, name: planName } = plan;
Expand Down Expand Up @@ -88,6 +89,7 @@ function PlanCardItem({ plan, onSelect }: Props) {
type={isFreePlan ? 'outline' : 'primary'}
size="large"
onClick={onSelect}
{...buttonProps}
/>
</div>
{planId === ReservedPlanId.Hobby && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReservedPlanId } from '@logto/schemas';
import { conditional } from '@silverhand/essentials';
import { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import Modal from 'react-modal';

Expand Down Expand Up @@ -27,6 +28,7 @@ type Props = {
};

function SelectTenantPlanModal({ tenantData, onClose }: Props) {
const [isSubmitting, setIsSubmitting] = useState<string>();
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data: subscriptionPlans } = useSubscriptionPlans();
const { subscribe } = useSubscribe();
Expand All @@ -40,6 +42,7 @@ function SelectTenantPlanModal({ tenantData, onClose }: Props) {
const handleSelectPlan = async (plan: SubscriptionPlan) => {
const { id: planId } = plan;
try {
setIsSubmitting(planId);
if (planId === ReservedPlanId.Free) {
const { name, tag, regionName } = tenantData;
const newTenant = await cloudApi.post('/api/tenants', { body: { name, tag, regionName } });
Expand All @@ -52,6 +55,8 @@ function SelectTenantPlanModal({ tenantData, onClose }: Props) {
await subscribe({ planId, tenantData });
} catch (error: unknown) {
void toastResponseError(error);
} finally {
setIsSubmitting(undefined);
}
};

Expand Down Expand Up @@ -82,6 +87,10 @@ function SelectTenantPlanModal({ tenantData, onClose }: Props) {
<PlanCardItem
key={plan.id}
plan={plan}
buttonProps={{
isLoading: isSubmitting === plan.id,
disabled: Boolean(isSubmitting),
}}
onSelect={() => {
void handleSelectPlan(plan);
}}
Expand Down
10 changes: 4 additions & 6 deletions packages/console/src/components/CreateTenantModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import CreateTenantHeaderIcon from '@/assets/icons/create-tenant-header.svg';
import { useCloudApi } from '@/cloud/hooks/use-cloud-api';
import { type TenantResponse } from '@/cloud/types/router';
import Region, { RegionName } from '@/components/Region';
import { isDevFeaturesEnabled } from '@/consts/env';
import Button from '@/ds-components/Button';
import DangerousRaw from '@/ds-components/DangerousRaw';
import FormField from '@/ds-components/FormField';
Expand Down Expand Up @@ -90,6 +89,7 @@ function CreateTenantModal({ isOpen, onClose }: Props) {
}
footer={
<Button
isLoading={isSubmitting}
disabled={isSubmitting}
htmlType="submit"
title="tenants.create_modal.create_button"
Expand All @@ -108,6 +108,7 @@ function CreateTenantModal({ isOpen, onClose }: Props) {
autoFocus
{...register('name', { required: true })}
error={Boolean(errors.name)}
disabled={isSubmitting}
/>
</FormField>
<FormField
Expand All @@ -126,14 +127,11 @@ function CreateTenantModal({ isOpen, onClose }: Props) {
key={region}
title={
<DangerousRaw>
<Region
regionName={region}
isComingSoon={!isDevFeaturesEnabled && region !== RegionName.EU}
/>
<Region regionName={region} />
</DangerousRaw>
}
value={region}
isDisabled={!isDevFeaturesEnabled && region !== RegionName.EU}
isDisabled={isSubmitting}
/>
))}
</RadioGroup>
Expand Down
10 changes: 2 additions & 8 deletions packages/console/src/onboarding/pages/CreateTenant/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import ActionBar from '@/components/ActionBar';
import { type CreateTenantData } from '@/components/CreateTenantModal/types';
import PageMeta from '@/components/PageMeta';
import Region, { RegionName } from '@/components/Region';
import { isDevFeaturesEnabled } from '@/consts/env';
import { TenantsContext } from '@/contexts/TenantsProvider';
import Button from '@/ds-components/Button';
import DangerousRaw from '@/ds-components/DangerousRaw';
Expand Down Expand Up @@ -132,16 +131,11 @@ function CreateTenant() {
key={region}
title={
<DangerousRaw>
<Region
regionName={region}
isComingSoon={!isDevFeaturesEnabled && region !== RegionName.EU}
/>
<Region regionName={region} />
</DangerousRaw>
}
value={region}
isDisabled={
isSubmitting || (!isDevFeaturesEnabled && region !== RegionName.EU)
}
isDisabled={isSubmitting}
/>
))}
</RadioGroup>
Expand Down
Loading