codogo-react-widgets
Version:
Provides a unified way to access the styling of commonly used widgets across different apps
51 lines (42 loc) • 2.97 kB
JavaScript
import _taggedTemplateLiteral from "babel-runtime/helpers/taggedTemplateLiteral";
var _templateObject = _taggedTemplateLiteral(["\n\tquery getUserID {\n\t\tuser {\n\t\t\tid\n\t\t}\n\t}\n"], ["\n\tquery getUserID {\n\t\tuser {\n\t\t\tid\n\t\t}\n\t}\n"]),
_templateObject2 = _taggedTemplateLiteral(["\n\tmutation createNewOrg {\n\t\tcreateOrg(name: \"New Org\") {\n\t\t\tid\n\t\t}\n\t}\n"], ["\n\tmutation createNewOrg {\n\t\tcreateOrg(name: \"New Org\") {\n\t\t\tid\n\t\t}\n\t}\n"]),
_templateObject3 = _taggedTemplateLiteral(["\n\tmutation($userId: ID!, $orgId: ID!) {\n\t\tcreateMembership(type: ADMIN, userId: $userId, orgId: $orgId) {\n\t\t\tid\n\t\t\torg {\n\t\t\t\tid\n\t\t\t\tmemberships {\n\t\t\t\t\tid\n\t\t\t\t\tuser {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tuser {\n\t\t\t\tid\n\t\t\t\tmemberships {\n\t\t\t\t\tid\n\t\t\t\t\ttype\n\t\t\t\t\torg {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcreateFolder(\n\t\t\torgId: $orgId\n\t\t\tparentOrgId: $orgId\n\t\t\tname: \"__ROOT_FOLDER__\"\n\t\t) {\n\t\t\tid\n\t\t\tname\n\t\t\torg {\n\t\t\t\tid\n\t\t\t\trootFolder {\n\t\t\t\t\tid\n\t\t\t\t\tname\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n"], ["\n\tmutation($userId: ID!, $orgId: ID!) {\n\t\tcreateMembership(type: ADMIN, userId: $userId, orgId: $orgId) {\n\t\t\tid\n\t\t\torg {\n\t\t\t\tid\n\t\t\t\tmemberships {\n\t\t\t\t\tid\n\t\t\t\t\tuser {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tuser {\n\t\t\t\tid\n\t\t\t\tmemberships {\n\t\t\t\t\tid\n\t\t\t\t\ttype\n\t\t\t\t\torg {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcreateFolder(\n\t\t\torgId: $orgId\n\t\t\tparentOrgId: $orgId\n\t\t\tname: \"__ROOT_FOLDER__\"\n\t\t) {\n\t\t\tid\n\t\t\tname\n\t\t\torg {\n\t\t\t\tid\n\t\t\t\trootFolder {\n\t\t\t\t\tid\n\t\t\t\t\tname\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n"]);
import React from "react";
import * as R from "ramda";
import { withHandlers, compose } from "recompose";
import gql from "graphql-tag";
import { withApollo, graphql } from "react-apollo";
import { AddOrgButton } from "../styles";
//------------------------------
var getUserID = gql(_templateObject);
var createNewOrg = gql(_templateObject2);
var addStuffToNewOrg = gql(_templateObject3);
var enhance = compose(graphql(getUserID, {
name: "getUserID"
}), withApollo, withHandlers({
addNewOrg: function addNewOrg(_ref) {
var client = _ref.client,
getUserID = _ref.getUserID;
return function () {
return client.mutate({
mutation: createNewOrg
}).then(R.path(["data", "createOrg", "id"])).then(function (orgId) {
return client.mutate({
mutation: addStuffToNewOrg,
variables: {
userId: R.path(["user", "id"], getUserID),
orgId: orgId
}
});
});
};
}
}));
export default enhance(function (props) {
return R.path(["getUserID", "user", "id"], props) ? React.createElement(
AddOrgButton,
{ onClick: props.addNewOrg, title: "Add new org" },
"Add new org"
) : null;
});