/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import "./view.scss"; import React from "react"; import { observer } from "mobx-react"; import { NamespaceSelect } from "../../../+namespaces/namespace-select"; import type { DialogProps } from "../../../dialog"; import { Dialog } from "../../../dialog"; import { Input } from "../../../input"; import { systemName } from "../../../input/input_validators"; import { SubTitle } from "../../../layout/sub-title"; import { Notifications } from "../../../notifications"; import { Wizard, WizardStep } from "../../../wizard"; import type { CreateServiceAccountDialogState } from "./state.injectable"; import type { ServiceAccountStore } from "../store"; import type { ShowDetails } from "../../../kube-detail-params/show-details.injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import closeCreateServiceAccountDialogInjectable from "./close.injectable"; import serviceAccountStoreInjectable from "../store.injectable"; import showDetailsInjectable from "../../../kube-detail-params/show-details.injectable"; import createServiceAccountDialogStateInjectable from "./state.injectable"; export interface CreateServiceAccountDialogProps extends Partial { } interface Dependencies { state: CreateServiceAccountDialogState; serviceAccountStore: ServiceAccountStore; closeCreateServiceAccountDialog: () => void; showDetails: ShowDetails; } @observer class NonInjectedCreateServiceAccountDialog extends React.Component { createAccount = async () => { const { closeCreateServiceAccountDialog, serviceAccountStore, state, showDetails } = this.props; try { const serviceAccount = await serviceAccountStore.create({ namespace: state.namespace.get(), name: state.name.get(), }); showDetails(serviceAccount.selfLink); closeCreateServiceAccountDialog(); } catch (err) { Notifications.checkedError(err, "Unknown error occured while creating service account"); } }; render() { const { closeCreateServiceAccountDialog, serviceAccountStore, state, ...dialogProps } = this.props; return ( Create Service Account} done={closeCreateServiceAccountDialog} > state.name.set(v.toLowerCase())} /> state.namespace.set(option?.value ?? "default")} /> ); } } export const CreateServiceAccountDialog = withInjectables(NonInjectedCreateServiceAccountDialog, { getProps: (di, props) => ({ ...props, closeCreateServiceAccountDialog: di.inject(closeCreateServiceAccountDialogInjectable), serviceAccountStore: di.inject(serviceAccountStoreInjectable), showDetails: di.inject(showDetailsInjectable), state: di.inject(createServiceAccountDialogStateInjectable), }), });