-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vincent T <[email protected]>
- Loading branch information
Showing
8 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
frontend/src/components/namespace/CreateNamespaceDialog.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,92 @@ | ||
import { | ||
Box, | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
TextField, | ||
Typography, | ||
} from '@mui/material'; | ||
import React, { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { post } from '../../lib/k8s/apiProxy'; | ||
import { ActionButton } from '../common'; | ||
|
||
interface CreateNamespaceButtonProps { | ||
toggleFunc: () => void; | ||
} | ||
|
||
export function CreateNamespaceButton({ toggleFunc }: CreateNamespaceButtonProps) { | ||
const { t } = useTranslation(['glossary', 'translation']); | ||
|
||
return ( | ||
<ActionButton | ||
color="primary" | ||
description={t('translation|Create')} | ||
icon={'mdi:plus-circle'} | ||
onClick={() => { | ||
toggleFunc(); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
interface CreateNamespaceDialogProps { | ||
isDialogOpen: boolean; | ||
toggleFunc: () => void; | ||
} | ||
export function CreateNamespaceDialog({ isDialogOpen, toggleFunc }: CreateNamespaceDialogProps) { | ||
const { t } = useTranslation(['glossary', 'translation']); | ||
const [namespaceName, setNamespaceName] = useState(''); | ||
|
||
function createNewNamespace() { | ||
const newNamespaceData = { | ||
apiVersion: 'v1', | ||
kind: 'Namespace', | ||
metadata: { | ||
name: namespaceName, | ||
}, | ||
}; | ||
|
||
async function createNamesapce(newNamespaceData: any) { | ||
try { | ||
const response = await post('/api/v1/namespaces', newNamespaceData); | ||
console.log('response', response); | ||
return response; | ||
} catch (error) { | ||
console.error('Error creating namespace', error); | ||
return error; | ||
} | ||
} | ||
|
||
createNamesapce(newNamespaceData); | ||
toggleFunc(); | ||
} | ||
|
||
return ( | ||
<> | ||
<Dialog open={isDialogOpen} onClose={() => toggleFunc()}> | ||
<DialogTitle>{t('translation|Create Namespace')}</DialogTitle> | ||
<DialogContent> | ||
<Box component="form"> | ||
<Typography>Please enter the name of the new namespace</Typography> | ||
<TextField | ||
margin="dense" | ||
id="name" | ||
label={t('glossary|Namespace')} | ||
type="text" | ||
fullWidth | ||
value={namespaceName} | ||
onChange={event => setNamespaceName(event.target.value)} | ||
/> | ||
</Box> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={() => toggleFunc()}>{t('translation|Cancel')}</Button> | ||
<Button onClick={() => createNewNamespace()}>{t('translation|Create')}</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</> | ||
); | ||
} |
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
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
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