The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
import { useMemo } from "react";
import { t } from "ttag";
import { useDispatch } from "metabase/redux";
import { addUndo } from "metabase/redux/undo";
import type { Location } from "metabase/router";
import { Modal } from "metabase/ui";
import { useCreateTenantMutation } from "metabase-enterprise/api";
import type { Tenant } from "metabase-types/api";
import { TenantForm } from "../../components/TenantForm";
interface NewUserModalProps {
onClose: () => void;
location?: Location;
}
export const NewTenantModal = ({ onClose, location }: NewUserModalProps) => {
const dispatch = useDispatch();
const [createTenant] = useCreateTenantMutation();
const isOnboarding = useMemo(() => {
const searchParams = new URLSearchParams(location?.search);
return searchParams.get("onboarding") === "true";
}, [location?.search]);
const handleSubmit = async (vals: Partial<Tenant>) => {
await createTenant({
...vals,
name: vals.name ?? "",
slug: vals.slug ?? "",
attributes: vals.attributes ?? {},
}).unwrap();
dispatch(addUndo({ message: t`Tenant creation successful` }));
onClose();
};
return (
<Modal
density="relaxed"
opened
title={isOnboarding ? t`Set up your first tenant` : t`New tenant`}
onClose={onClose}
>
<TenantForm
initialValues={{}}
submitText={t`Create tenant`}
onCancel={onClose}
onSubmit={handleSubmit}
/>
</Modal>
);
};