mirror of
https://github.com/Telecominfraproject/wlan-cloud-ui.git
synced 2025-11-02 19:57:58 +00:00
added getting latest User
This commit is contained in:
@@ -1,10 +1,23 @@
|
|||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { EditAccount as EditAccountPage } from '@tip-wlan/wlan-cloud-ui-library';
|
import { EditAccount as EditAccountPage } from '@tip-wlan/wlan-cloud-ui-library';
|
||||||
import gql from 'graphql-tag';
|
import gql from 'graphql-tag';
|
||||||
import { useMutation } from '@apollo/react-hooks';
|
import { useMutation, useQuery } from '@apollo/react-hooks';
|
||||||
import { notification } from 'antd';
|
import { notification, Spin, Alert } from 'antd';
|
||||||
|
|
||||||
import UserContext from 'contexts/UserContext';
|
import UserContext from 'contexts/UserContext';
|
||||||
|
|
||||||
|
const GET_USER = gql`
|
||||||
|
query GetUser($id: Int!) {
|
||||||
|
getUser(id: $id) {
|
||||||
|
id
|
||||||
|
username
|
||||||
|
role
|
||||||
|
customerId
|
||||||
|
lastModifiedTimestamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
const UPDATE_USER = gql`
|
const UPDATE_USER = gql`
|
||||||
mutation UpdateUser(
|
mutation UpdateUser(
|
||||||
$id: Int!
|
$id: Int!
|
||||||
@@ -32,10 +45,13 @@ const UPDATE_USER = gql`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const EditAccount = () => {
|
const EditAccount = () => {
|
||||||
const { id, email, role, customerId, lastModifiedTimestamp } = useContext(UserContext);
|
const { id, email } = useContext(UserContext);
|
||||||
|
const { loading, error, data } = useQuery(GET_USER, { variables: { id } });
|
||||||
const [updateUser] = useMutation(UPDATE_USER);
|
const [updateUser] = useMutation(UPDATE_USER);
|
||||||
|
|
||||||
const handleSubmit = newPassword => {
|
const handleSubmit = newPassword => {
|
||||||
|
const { role, customerId, lastModifiedTimestamp } = data.getUser;
|
||||||
|
|
||||||
updateUser({
|
updateUser({
|
||||||
variables: {
|
variables: {
|
||||||
id,
|
id,
|
||||||
@@ -60,6 +76,14 @@ const EditAccount = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <Spin size="large" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <Alert message="Error" description="Failed to load User." type="error" showIcon />;
|
||||||
|
}
|
||||||
|
|
||||||
return <EditAccountPage onSubmit={handleSubmit} email={email} />;
|
return <EditAccountPage onSubmit={handleSubmit} email={email} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user