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.
🪟 🎉 Allow setting organization name (#8396)
- Loading branch information
1 parent
645e82c
commit 271babb
Showing
3 changed files
with
84 additions
and
8 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
72 changes: 65 additions & 7 deletions
72
airbyte-webapp/src/pages/SettingsPage/GeneralOrganizationSettingsPage.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 |
---|---|---|
@@ -1,25 +1,83 @@ | ||
import { FormattedMessage } from "react-intl"; | ||
import React, { useEffect } from "react"; | ||
import { FormattedMessage, useIntl } from "react-intl"; | ||
import * as yup from "yup"; | ||
import { AnySchema } from "yup"; | ||
|
||
import { Form, FormControl } from "components/forms"; | ||
import { FormSubmissionButtons } from "components/forms/FormSubmissionButtons"; | ||
import { Box } from "components/ui/Box"; | ||
import { Card } from "components/ui/Card"; | ||
import { Text } from "components/ui/Text"; | ||
|
||
import { useCurrentWorkspace } from "core/api"; | ||
import { useCurrentWorkspace, useUpdateOrganization } from "core/api"; | ||
import { useOrganization } from "core/api"; | ||
import { OrganizationUpdateRequestBody } from "core/request/AirbyteClient"; | ||
import { useNotificationService } from "hooks/services/Notification"; | ||
|
||
const ORGANIZATION_UPDATE_NOTIFICATION_ID = "organization-update-notification"; | ||
|
||
const organizationValidationSchema = yup.object().shape<Record<keyof OrganizationFormValues, AnySchema>>({ | ||
organizationName: yup.string().trim().required("form.empty.error"), | ||
}); | ||
|
||
type OrganizationFormValues = Pick<OrganizationUpdateRequestBody, "organizationName">; | ||
|
||
export const GeneralOrganizationSettingsPage: React.FC = () => { | ||
const { organizationId } = useCurrentWorkspace(); | ||
|
||
return ( | ||
<Card title={<FormattedMessage id="settings.generalSettings" />}> | ||
<Box p="xl">{organizationId && <Organization organizationId={organizationId} />}</Box> | ||
<Box p="xl">{organizationId && <OrganizationSettingsForm organizationId={organizationId} />}</Box> | ||
</Card> | ||
); | ||
}; | ||
|
||
const Organization = ({ organizationId }: { organizationId: string }) => { | ||
const OrganizationSettingsForm = ({ organizationId }: { organizationId: string }) => { | ||
const organization = useOrganization(organizationId); | ||
const { mutateAsync: updateOrganization } = useUpdateOrganization(); | ||
|
||
const { formatMessage } = useIntl(); | ||
const { registerNotification, unregisterNotificationById } = useNotificationService(); | ||
|
||
const onSubmit = async (values: OrganizationFormValues) => { | ||
await updateOrganization({ | ||
organizationId, | ||
...values, | ||
}); | ||
}; | ||
|
||
// Placeholder for organization information and settings | ||
return <Text>{organization.organizationName}</Text>; | ||
useEffect( | ||
() => () => { | ||
unregisterNotificationById(ORGANIZATION_UPDATE_NOTIFICATION_ID); | ||
}, | ||
[unregisterNotificationById] | ||
); | ||
|
||
return ( | ||
<Form<OrganizationFormValues> | ||
onSubmit={onSubmit} | ||
onSuccess={() => { | ||
registerNotification({ | ||
id: ORGANIZATION_UPDATE_NOTIFICATION_ID, | ||
text: formatMessage({ id: "form.changesSaved" }), | ||
type: "success", | ||
}); | ||
}} | ||
onError={() => { | ||
registerNotification({ | ||
id: ORGANIZATION_UPDATE_NOTIFICATION_ID, | ||
text: formatMessage({ id: "form.someError" }), | ||
type: "error", | ||
}); | ||
}} | ||
schema={organizationValidationSchema} | ||
defaultValues={{ organizationName: organization.organizationName }} | ||
> | ||
<FormControl<OrganizationFormValues> | ||
label={formatMessage({ id: "settings.organizationSettings.organizationName" })} | ||
fieldType="input" | ||
name="organizationName" | ||
/> | ||
<FormSubmissionButtons submitKey="form.saveChanges" /> | ||
</Form> | ||
); | ||
}; |