Skip to content

Commit

Permalink
feat(web): update story custom domain extension (#1361)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomokazu Tantaka <[email protected]>
  • Loading branch information
hexaforce and hexaforce committed Jan 22, 2025
1 parent 4fc9174 commit 16102a1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { AssetField, InputField, SwitchField } from "@reearth/beta/ui/fields";
import TextAreaField from "@reearth/beta/ui/fields/TextareaField";
import { Story } from "@reearth/services/api/storytellingApi/utils";
import { useAuth } from "@reearth/services/auth";
import {
ProjectPublicationExtensionProps,
StoryPublicationExtensionProps
} from "@reearth/services/config/extensions";
import { useLang, useT } from "@reearth/services/i18n";
import {
NotificationType,
Expand Down Expand Up @@ -104,6 +108,18 @@ const PublicSettingsDetail: React.FC<Props> = ({
[setNotification]
);

const ExtensionComponent = (
props: ProjectPublicationExtensionProps | StoryPublicationExtensionProps
) => {
const type = props.typename.toLocaleLowerCase();
const extensionId = `custom-${type}-domain`;
const Component = extensions?.find((e) => e.id === extensionId)?.component;
if (!Component) {
return null;
}
return <Component {...props} />;
};

return (
<>
<Collapse title={t("Public Info")} size="large">
Expand Down Expand Up @@ -233,22 +249,31 @@ const PublicSettingsDetail: React.FC<Props> = ({
</ButtonWrapper>
</SettingsFields>
</Collapse>
{extensions && extensions.length > 0 && accessToken && (
<Collapse title={t("Custom Domain")} size="large">
{extensions.map((ext) => (
<ext.component
key={ext.id}
projectId={settingsItem.id}
projectAlias={settingsItem.alias}
{extensions &&
extensions.length > 0 &&
settingsItem.typename &&
accessToken && (
<Collapse title={t("Custom Domain")} size="large">
<ExtensionComponent
typename={settingsItem.typename}
key={settingsItem.id}
{...(settingsItem.typename === "Project"
? {
projectId: settingsItem.id,
projectAlias: settingsItem.alias
}
: {
storyId: settingsItem.id,
storyAlias: settingsItem.alias
})}
lang={currentLang}
theme={currentTheme}
accessToken={accessToken}
onNotificationChange={onNotificationChange}
version={"visualizer"}
version="visualizer"
/>
))}
</Collapse>
)}
</Collapse>
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type SettingsProject = {
isArchived: boolean;
enableGa: boolean;
trackingId: string;
typename?: "Project";
};

type Props = {
Expand Down
1 change: 1 addition & 0 deletions web/src/services/api/storytellingApi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type Story = {
pages?: Page[];
trackingId?: string; // Not supported yet
enableGa?: boolean; // Not supported yet
typename?: "Story";
};

export const getStories = (rawScene?: GetSceneQuery) => {
Expand Down
12 changes: 11 additions & 1 deletion web/src/services/config/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export type ProjectPublicationExtensionProps = {
projectId: string;
projectAlias?: string;
publishDisabled?: boolean;
typename: string;
} & SharedExtensionProps;

export type StoryPublicationExtensionProps = {
storyId: string;
storyAlias?: string;
publishDisabled?: boolean;
typename: string;
} & SharedExtensionProps;

export type PluginExtensionProps = {
Expand All @@ -50,7 +58,9 @@ export type GlobalModalProps = {

export type ExtensionProps = {
"dataset-import": DatasetImportExtensionProps;
publication: ProjectPublicationExtensionProps;
publication:
| ProjectPublicationExtensionProps
| StoryPublicationExtensionProps;
"plugin-library": PluginExtensionProps;
"plugin-installed": PluginExtensionProps;
"global-modal": GlobalModalProps;
Expand Down

0 comments on commit 16102a1

Please sign in to comment.