add/update profile mutations

This commit is contained in:
Irtiza-h30
2020-06-09 12:12:39 -04:00
parent 48e7fd2b8c
commit 7d572a9725
3 changed files with 129 additions and 2 deletions

View File

@@ -0,0 +1,63 @@
import React, { useContext } from 'react';
import { AddProfile as AddProfilePage } from '@tip-wlan/wlan-cloud-ui-library';
import gql from 'graphql-tag';
import { useMutation } from '@apollo/react-hooks';
import { notification } from 'antd';
import UserContext from 'contexts/UserContext';
const CREATE_PROFILE = gql`
mutation CreateProfile(
$profileType: String!
$customerId: Int!
$name: String!
$childProfileIds: [Int]
$details: JSONObject
) {
createProfile(
profileType: $profileType
customerId: $customerId
name: $name
childProfileIds: $childProfileIds
details: $details
) {
profileType
customerId
name
childProfileIds
details
}
}
`;
const AddProfile = () => {
const { customerId, childProfileIds } = useContext(UserContext);
const [createProfile] = useMutation(CREATE_PROFILE);
const handleAddProfile = (profileType, name, details) => {
createProfile({
variables: {
profileType,
customerId,
name,
childProfileIds,
details,
},
})
.then(() => {
notification.success({
message: 'Success',
description: 'Profile successfully created.',
});
})
.catch(() =>
notification.error({
message: 'Error',
description: 'Profile could not be created.',
})
);
};
return <AddProfilePage onCreateProfile={handleAddProfile} />;
};
export default AddProfile;