diff --git a/src/components/SshKeys/AddSshKey.js b/src/components/SshKeys/AddSshKey.js index 4a25d43a..47d399c9 100644 --- a/src/components/SshKeys/AddSshKey.js +++ b/src/components/SshKeys/AddSshKey.js @@ -1,10 +1,11 @@ import React, { useState } from 'react'; import { Mutation } from 'react-apollo'; +import { Space } from 'antd'; import Button from 'components/Button'; import Me from 'lib/query/Me'; -import AddSshKeyMutation from '../../lib/mutation/AddSshKey'; +import AddUserSSHPublicKey from '../../lib/mutation/AddUserSSHPublicKey'; const AddSshKey = ({ me: { id, email } }) => { const defaultValues = { sshKeyName: '', sshKey: '' }; @@ -15,24 +16,16 @@ const AddSshKey = ({ me: { id, email } }) => { setValues({ ...values, [name]: value }); }; - const regex = /\s*(ssh-rsa|ssh-ed25519|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521)\s(\S+)/; - // First capture group is the type of the ssh key - // Second capture group is the actual ssh key - // Whitespace and comments are ignored - - const isFormValid = values.sshKeyName !== '' && !values.sshKey.includes('\n') && values.sshKey.match(regex); - return (
- - {(addSshKey, { loading, called, error, data }) => { + console.error(e)}> + {(addUserSSHPublicKey, { loading, called, error, data }) => { const addSshKeyHandler = () => { - addSshKey({ + addUserSSHPublicKey({ variables: { input: { name: values.sshKeyName, - keyValue: values.sshKey.match(regex)[2], - keyType: values.sshKey.match(regex)[1].replace(/-/g, '_').toUpperCase(), + publicKey: values.sshKey, user: { id, email, @@ -40,17 +33,12 @@ const AddSshKey = ({ me: { id, email } }) => { }, }, }); + setValues(defaultValues); }; - if (!error && called && loading) { - return
Adding SSH Key...
; - } - return (
- {error ?
{error.message.replace('GraphQL error:', '').trim()}
: ''} -
{ placeholder="Begins with 'ssh-rsa', 'ssh-ed25519', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521'" />
- -
- - {values.sshKeyName == '' ? 'Please enter a SSH Key name' : 'The SSH Key entered is invalid'} - -
+ + + + {error ?
{error.message.replace('GraphQL error:', '').trim()}
: ''} +
); }} diff --git a/src/components/SshKeys/index.js b/src/components/SshKeys/index.js index d1ec375e..abaa4fe1 100644 --- a/src/components/SshKeys/index.js +++ b/src/components/SshKeys/index.js @@ -2,16 +2,36 @@ import React, { useEffect, useState } from 'react'; import { Mutation } from 'react-apollo'; import Skeleton from 'react-loading-skeleton'; +import { Col, Modal, Row, Space } from 'antd'; import Button from 'components/Button'; -import DeleteSshKeyById from 'lib/mutation/DeleteSshKeyById'; +import DeleteUserSSHPublicKey from 'lib/mutation/DeleteUserSSHPublicKey'; +import UpdateUserSSHPublicKey from 'lib/mutation/UpdateUserSSHPublicKey'; import Me from 'lib/query/Me'; import moment from 'moment'; import { StyledKeys } from './StyledKeys'; -const SshKeys = ({ me: { id, email, sshKeys: keys }, loading }) => { +const SshKeys = ({ me: { id, email, sshKeys: keys }, loading, handleRefetch }) => { const [isLoading, setIsLoading] = useState(loading); + const [modalOpen, setModalOpen] = useState(false); + + const [editState, setEditState] = useState({ + id: '', + name: '', + publicKey: '', + }); + + const closeModal = () => { + setEditState({ name: '', publicKey: '' }); + setModalOpen(false); + }; + + const openModal = keyObject => { + setEditState(keyObject); + setModalOpen(true); + }; + useEffect(() => { setIsLoading(loading); }, [loading]); @@ -41,36 +61,127 @@ const SshKeys = ({ me: { id, email, sshKeys: keys }, loading }) => {
{moment.utc(key.created).local().format('DD MMM YYYY, HH:mm:ss (Z)')}
-
- - {(deleteSshKeyById, { loading, called, error, data }) => { - if (error) { - return
{error.message}
; - } - - if (called) { - return
Deleting SSH Key...
; - } - return ( - + ( + <> + + console.error(e)}> + {(updateUserSSHPublicKey, { loading, called, error, data }) => { + if (error) { + return
{error.message}
; + } + + if (data) { + handleRefetch(); + closeModal(); + } + + return ( + + ); + }} +
+ + +
+ + )} + > + + SSH KEY NAME: + + + { + setEditState({ ...editState, name: e.target.value }); + }} + /> + + + + + SSH KEY: + + { + setEditState({ ...editState, publicKey: e.target.value }); + }} + /> + + +
+
+ +
+ console.error(e)} + > + {(deleteUserSSHPublicKey, { loading, called, error, data }) => { + if (error) { + return
{error.message}
; + } + + return ( + - ); - }} -
-
+ }) + } + > + Delete + + ); + }} +
+
+ ))} diff --git a/src/layouts/GlobalStyles/index.tsx b/src/layouts/GlobalStyles/index.tsx index 401b7a36..0866b67c 100644 --- a/src/layouts/GlobalStyles/index.tsx +++ b/src/layouts/GlobalStyles/index.tsx @@ -67,6 +67,24 @@ body { background: ${props => (props.theme.colorScheme === 'dark' ? '#fff' : '#000')}; } } +.ant-modal .ant-modal-content{ + background: ${props => (props.theme.colorScheme === 'dark' ? '#eaeaea' : '#fff')}; + .ant-modal-header{ + border-radius: 0; + background-color: transparent; + } + .ant-modal-body { + margin-block: 1rem; + > * { + margin-bottom: 0.5rem; + } + } + + input.fullSize{ + width: 100%; + padding: 0.25rem 0.5rem; + } +} #__next { display: flex; diff --git a/src/lib/mutation/AddSshKey.js b/src/lib/mutation/AddSshKey.js deleted file mode 100644 index d354ae28..00000000 --- a/src/lib/mutation/AddSshKey.js +++ /dev/null @@ -1,12 +0,0 @@ -import gql from 'graphql-tag'; - -export default gql` - mutation addSshKey($input: AddSshKeyInput!) { - addSshKey(input: $input) { - id - name - keyType - created - } - } -`; diff --git a/src/lib/mutation/AddUserSSHPublicKey.js b/src/lib/mutation/AddUserSSHPublicKey.js new file mode 100644 index 00000000..f15d7f0c --- /dev/null +++ b/src/lib/mutation/AddUserSSHPublicKey.js @@ -0,0 +1,12 @@ +import gql from 'graphql-tag'; + +export default gql` + mutation addUserSSHPublicKey($input: AddUserSSHPublicKeyInput!) { + addUserSSHPublicKey(input: $input) { + id + name + keyValue + created + } + } +`; diff --git a/src/lib/mutation/DeleteSshKeyById.js b/src/lib/mutation/DeleteSshKeyById.js deleted file mode 100644 index b44ab15c..00000000 --- a/src/lib/mutation/DeleteSshKeyById.js +++ /dev/null @@ -1,7 +0,0 @@ -import gql from 'graphql-tag'; - -export default gql` - mutation deleteSshKeyById($input: DeleteSshKeyByIdInput!) { - deleteSshKeyById(input: $input) - } -`; diff --git a/src/lib/mutation/DeleteUserSSHPublicKey.js b/src/lib/mutation/DeleteUserSSHPublicKey.js new file mode 100644 index 00000000..eb06b3b7 --- /dev/null +++ b/src/lib/mutation/DeleteUserSSHPublicKey.js @@ -0,0 +1,7 @@ +import gql from 'graphql-tag'; + +export default gql` + mutation deleteUserSSHPublicKey($input: DeleteUserSSHPublicKeyByIdInput!) { + deleteUserSSHPublicKey(input: $input) + } +`; diff --git a/src/lib/mutation/UpdateUserSSHPublicKey.js b/src/lib/mutation/UpdateUserSSHPublicKey.js new file mode 100644 index 00000000..f35312aa --- /dev/null +++ b/src/lib/mutation/UpdateUserSSHPublicKey.js @@ -0,0 +1,11 @@ +import gql from 'graphql-tag'; + +export default gql` + mutation updateUserSSHPublicKey($input: UpdateUserSSHPublicKeyInput!) { + updateUserSSHPublicKey(input: $input) { + id + name + keyValue + } + } +`; diff --git a/src/pages/settings/index.js b/src/pages/settings/index.js index 13b05c4c..28c66034 100644 --- a/src/pages/settings/index.js +++ b/src/pages/settings/index.js @@ -15,10 +15,13 @@ import { CommonWrapper } from '../../styles/commonPageStyles'; * Displays the user settings page. */ const SettingsPage = () => { - const { data, loading, error } = useQuery(Me, { + const queryVars = { displayName: 'Me', fetchPolicy: 'cache-and-network', - }); + }; + const { data, loading, error, refetch } = useQuery(Me, queryVars); + + const handleRefetch = async () => await refetch(queryVars); if (error) { return ; @@ -33,7 +36,7 @@ const SettingsPage = () => {

SSH keys

- +