forked from airbytehq/airbyte-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟 🔧 Associate newly created oss workspaces with organization (#8857)
- Loading branch information
1 parent
73ed4c6
commit efe23db
Showing
9 changed files
with
268 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,15 @@ | |
"workspaces.title": "Workspaces", | ||
"workspaces.subtitle": "Workspaces let you collaborate with team members and share connections across your team.", | ||
"workspaces.create": "Create workspace", | ||
"workspaces.create.organizationDescription": "This workspace will be created in the organization <b>{organizationName}</b>", | ||
"workspaces.createSuccess": "Workspace created successfully", | ||
"workspaces.createError": "Something went wrong while creating the workspace. Please try again.", | ||
"workspaces.createNew": "New workspace", | ||
"workspaces.createFirst": "Create your first workspace", | ||
"workspaces.loading": "Loading…", | ||
"workspaces.noWorkspaces": "No workspaces found", | ||
"workspaces.workspace": "Workspace", | ||
"workspaces.seeAll": "See all workspaces", | ||
"workspaces.name": "Workspace name", | ||
|
||
"user.roleLabel": "Role: {role}", | ||
"role.admin": "Admin", | ||
|
@@ -53,6 +54,7 @@ | |
"form.email.placeholder": "[email protected]", | ||
"form.organizationName": "Organization name", | ||
"form.organizationName.placeholder": "ACME Corp", | ||
"form.workspaceName": "Workspace name", | ||
"form.email.error": "Enter a valid email", | ||
"form.empty.error": "Required", | ||
"form.selectValue": "Select a value", | ||
|
106 changes: 106 additions & 0 deletions
106
...ebapp/src/packages/cloud/views/workspaces/WorkspacesPage/CloudWorkspacesCreateControl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { UseMutateAsyncFunction } from "@tanstack/react-query"; | ||
import React from "react"; | ||
import { FormattedMessage, useIntl } from "react-intl"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useToggle } from "react-use"; | ||
import * as yup from "yup"; | ||
|
||
import { Form, FormControl } from "components/forms"; | ||
import { FormSubmissionButtons } from "components/forms/FormSubmissionButtons"; | ||
import { Box } from "components/ui/Box"; | ||
import { Button } from "components/ui/Button"; | ||
import { Card } from "components/ui/Card"; | ||
import { Icon } from "components/ui/Icon"; | ||
|
||
import { useListWorkspaces } from "core/api"; | ||
import { CloudWorkspaceRead } from "core/api/types/CloudApi"; | ||
import { trackError } from "core/utils/datadog"; | ||
import { useNotificationService } from "hooks/services/Notification"; | ||
import styles from "pages/workspaces/components/WorkspacesCreateControl.module.scss"; | ||
|
||
interface CreateCloudWorkspaceFormValues { | ||
name: string; | ||
} | ||
|
||
const CreateCloudWorkspaceFormValidationSchema = yup.object().shape({ | ||
name: yup.string().trim().required("form.empty.error"), | ||
}); | ||
|
||
interface CloudWorkspacesCreateControlProps { | ||
createWorkspace: UseMutateAsyncFunction<CloudWorkspaceRead, unknown, string, unknown>; | ||
} | ||
|
||
export const CloudWorkspacesCreateControl: React.FC<CloudWorkspacesCreateControlProps> = ({ createWorkspace }) => { | ||
const navigate = useNavigate(); | ||
const { formatMessage } = useIntl(); | ||
const [isEditMode, toggleMode] = useToggle(false); | ||
const { registerNotification } = useNotificationService(); | ||
const { workspaces } = useListWorkspaces(); | ||
const isFirstWorkspace = workspaces.length === 0; | ||
|
||
const onSubmit = async (values: CreateCloudWorkspaceFormValues) => { | ||
const newWorkspace = await createWorkspace(values.name); | ||
toggleMode(); | ||
navigate(`/workspaces/${newWorkspace.workspaceId}`); | ||
}; | ||
|
||
const onSuccess = () => { | ||
registerNotification({ | ||
id: "workspaces.createSuccess", | ||
text: formatMessage({ id: "workspaces.createSuccess" }), | ||
type: "success", | ||
}); | ||
}; | ||
|
||
const onError = (e: Error, { name }: CreateCloudWorkspaceFormValues) => { | ||
trackError(e, { name }); | ||
registerNotification({ | ||
id: "workspaces.createError", | ||
text: formatMessage({ id: "workspaces.createError" }), | ||
type: "error", | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
{isEditMode ? ( | ||
<Card withPadding className={styles.animate}> | ||
<Form<CreateCloudWorkspaceFormValues> | ||
defaultValues={{ | ||
name: "", | ||
}} | ||
schema={CreateCloudWorkspaceFormValidationSchema} | ||
onSubmit={onSubmit} | ||
onSuccess={onSuccess} | ||
onError={onError} | ||
> | ||
<FormControl<CreateCloudWorkspaceFormValues> | ||
label={formatMessage({ id: "form.workspaceName" })} | ||
name="name" | ||
fieldType="input" | ||
type="text" | ||
/> | ||
<FormSubmissionButtons | ||
submitKey="form.saveChanges" | ||
onCancelClickCallback={toggleMode} | ||
allowNonDirtyCancel | ||
/> | ||
</Form> | ||
</Card> | ||
) : ( | ||
<Box> | ||
<Button | ||
onClick={toggleMode} | ||
variant="secondary" | ||
data-testid="workspaces.createNew" | ||
size="lg" | ||
icon={<Icon type="plus" />} | ||
className={styles.createButton} | ||
> | ||
<FormattedMessage id={isFirstWorkspace ? "workspaces.createFirst" : "workspaces.createNew"} /> | ||
</Button> | ||
</Box> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.