Skip to content

Commit

Permalink
Display a message if custom smtp is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
tung2744 committed Dec 6, 2024
1 parent 83d0d28 commit c5cf909
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion portal/src/BlueMessageBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function BlueMessageBar(
);

return (
<ThemeProvider theme={newTheme}>
<ThemeProvider as={React.Fragment} theme={newTheme}>
<MessageBar styles={styles} {...rest} />
</ThemeProvider>
);
Expand Down
33 changes: 28 additions & 5 deletions portal/src/graphql/portal/SMTPConfigurationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import DefaultButton from "../../DefaultButton";
import { AppSecretKey } from "./globalTypes.generated";
import { useLocationEffect } from "../../hook/useLocationEffect";
import { useAppSecretVisitToken } from "./mutations/generateAppSecretVisitTokenMutation";
import { useAppFeatureConfigQuery } from "./query/appFeatureConfigQuery";
import FeatureDisabledMessageBar from "./FeatureDisabledMessageBar";

interface LocationState {
isEdit: boolean;
Expand Down Expand Up @@ -245,13 +247,14 @@ function ProviderDescription(props: ProviderDescriptionProps) {
}

interface SMTPConfigurationScreenContentProps {
isCustomSMTPDisabled: boolean;
sendTestEmailHandle: UseSendTestEmailMutationReturnType;
form: AppSecretConfigFormModel<FormState>;
}

const SMTPConfigurationScreenContent: React.VFC<SMTPConfigurationScreenContentProps> =
function SMTPConfigurationScreenContent(props) {
const { form, sendTestEmailHandle } = props;
const { form, sendTestEmailHandle, isCustomSMTPDisabled } = props;
const { state, setState } = form;
const { sendTestEmail, loading } = sendTestEmailHandle;

Expand Down Expand Up @@ -503,6 +506,12 @@ const SMTPConfigurationScreenContent: React.VFC<SMTPConfigurationScreenContentPr
<ScreenDescription className={styles.widget}>
<FormattedMessage id="SMTPConfigurationScreen.description" />
</ScreenDescription>
{isCustomSMTPDisabled ? (
<FeatureDisabledMessageBar
className={styles.widget}
messageID="FeatureConfig.custom-smtp.disabled"
/>
) : null}

<Widget className={styles.widget} contentLayout="grid">
<Toggle
Expand All @@ -511,7 +520,7 @@ const SMTPConfigurationScreenContent: React.VFC<SMTPConfigurationScreenContentPr
onChange={onChangeEnabled}
label={renderToString("SMTPConfigurationScreen.enable.label")}
inlineLabel={true}
disabled={state.isPasswordMasked}
disabled={state.isPasswordMasked || isCustomSMTPDisabled}
/>
{state.enabled ? (
<>
Expand Down Expand Up @@ -622,6 +631,7 @@ const SMTPConfigurationScreenContent: React.VFC<SMTPConfigurationScreenContentPr
{state.isPasswordMasked ? (
<PrimaryButton
className={styles.columnSmall}
disabled={isCustomSMTPDisabled}
onClick={onClickEdit}
text={<FormattedMessage id="edit" />}
/>
Expand Down Expand Up @@ -678,20 +688,33 @@ const SMTPConfigurationScreen1: React.VFC<{
constructConfig,
constructSecretUpdateInstruction,
});
const featureConfig = useAppFeatureConfigQuery(appID);

const sendTestEmailHandle = useSendTestEmailMutation(appID);

if (form.isLoading) {
if (form.isLoading || featureConfig.loading) {
return <ShowLoading />;
}

if (form.loadError) {
return <ShowError error={form.loadError} onRetry={form.reload} />;
if (form.loadError ?? featureConfig.error) {
return (
<ShowError
error={form.loadError ?? featureConfig.error}
onRetry={() => {
form.reload();
featureConfig.refetch().finally(() => {});
}}
/>
);
}

return (
<FormContainer form={form} localError={sendTestEmailHandle.error}>
<SMTPConfigurationScreenContent
isCustomSMTPDisabled={
featureConfig.effectiveFeatureConfig?.messaging
?.custom_smtp_disabled ?? false
}
sendTestEmailHandle={sendTestEmailHandle}
form={form}
/>
Expand Down
1 change: 1 addition & 0 deletions portal/src/locale-data/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@
"FeatureConfig.collaborator.contact-us": "Your plan only include {maximum, plural, one{1 member seat} other{# member seats}}, {ExternalLink, react, href{{contactUsHref}} children{contact us to upgrade} target{_blank}}",
"FeatureConfig.web3-nft.maximum": "You can index {maximum, plural, one{1 collection} other{# collections}} max. {ReactRouterLink, react, to{{planPagePath}} children{Upgrade your project plan} target{_blank}} to add more",
"FeatureConfig.edit-template.disabled": "{ReactRouterLink, react, to{{planPagePath}} children{Upgrade your project plan} target{_blank}} to change the templates.",
"FeatureConfig.custom-smtp.disabled": "Custom email provider is not available for your project plan. {ReactRouterLink, react, to{{planPagePath}} children{Upgrade your project plan} target{_blank}}.",
"SubscriptionCurrentPlanSummary.title.known-plan": "Current Plan: {name} {expiredAt, select, false{(${amount}/mo)} other{(Expire at: {expiredAt})}}",
"SubscriptionCurrentPlanSummary.title.custom-plan": "Custom Plan: {name}",
"SubscriptionCurrentPlanSummary.label.free": "Free",
Expand Down

0 comments on commit c5cf909

Please sign in to comment.