Add default token
This commit is contained in:
parent
4801bd6fa0
commit
c7b650b27a
12 changed files with 246 additions and 83 deletions
|
@ -0,0 +1,98 @@
|
||||||
|
import Button from "@material-ui/core/Button";
|
||||||
|
import Card from "@material-ui/core/Card";
|
||||||
|
import CardContent from "@material-ui/core/CardContent";
|
||||||
|
import IconButton from "@material-ui/core/IconButton";
|
||||||
|
import Paper from "@material-ui/core/Paper";
|
||||||
|
import { Theme } from "@material-ui/core/styles";
|
||||||
|
import { fade } from "@material-ui/core/styles/colorManipulator";
|
||||||
|
import Typography from "@material-ui/core/Typography";
|
||||||
|
import CloseIcon from "@material-ui/icons/Close";
|
||||||
|
import { makeStyles } from "@material-ui/styles";
|
||||||
|
import React from "react";
|
||||||
|
import { FormattedMessage } from "react-intl";
|
||||||
|
|
||||||
|
export interface ServiceDefaultTokenProps {
|
||||||
|
token: string;
|
||||||
|
onTokenClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const useStyles = makeStyles(
|
||||||
|
(theme: Theme) => ({
|
||||||
|
cancel: {
|
||||||
|
marginRight: theme.spacing.unit
|
||||||
|
},
|
||||||
|
closeContainer: {
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "flex-end",
|
||||||
|
position: "relative",
|
||||||
|
right: -theme.spacing.unit,
|
||||||
|
top: -theme.spacing.unit
|
||||||
|
},
|
||||||
|
copy: {
|
||||||
|
marginTop: theme.spacing.unit,
|
||||||
|
position: "relative",
|
||||||
|
right: theme.spacing.unit
|
||||||
|
},
|
||||||
|
paper: {
|
||||||
|
background: fade(theme.palette.primary.main, 0.05),
|
||||||
|
padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit * 3}px`
|
||||||
|
},
|
||||||
|
root: {
|
||||||
|
boxShadow: "0px 5px 10px rgba(0, 0, 0, 0.05)"
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
display: "grid",
|
||||||
|
gridColumnGap: theme.spacing.unit * 3 + "px",
|
||||||
|
gridTemplateColumns: "1fr 60px",
|
||||||
|
marginBottom: theme.spacing.unit * 3
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
name: "ServiceTokenCreateDialog"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
function handleCopy(token: string) {
|
||||||
|
navigator.clipboard.writeText(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ServiceDefaultToken: React.FC<ServiceDefaultTokenProps> = props => {
|
||||||
|
const { token, onTokenClose } = props;
|
||||||
|
const classes = useStyles(props);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className={classes.root}>
|
||||||
|
<CardContent>
|
||||||
|
<div className={classes.text}>
|
||||||
|
<Typography>
|
||||||
|
<FormattedMessage defaultMessage="We’ve created your default token. Make sure to copy your new personal access token now. You won’t be able to see it again." />
|
||||||
|
</Typography>
|
||||||
|
<div className={classes.closeContainer}>
|
||||||
|
<IconButton onClick={onTokenClose}>
|
||||||
|
<CloseIcon />
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Paper className={classes.paper} elevation={0}>
|
||||||
|
<Typography variant="caption">
|
||||||
|
<FormattedMessage defaultMessage="Generated Token" />
|
||||||
|
</Typography>
|
||||||
|
<Typography>{token}</Typography>
|
||||||
|
<Button
|
||||||
|
className={classes.copy}
|
||||||
|
color="primary"
|
||||||
|
onClick={() => handleCopy(token)}
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="Copy token"
|
||||||
|
description="button"
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</Paper>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
ServiceDefaultToken.displayName = "ServiceDefaultToken";
|
||||||
|
export default ServiceDefaultToken;
|
2
src/services/components/ServiceDefaultToken/index.ts
Normal file
2
src/services/components/ServiceDefaultToken/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export { default } from "./ServiceDefaultToken";
|
||||||
|
export * from "./ServiceDefaultToken";
|
|
@ -15,11 +15,13 @@ const props: ServiceDetailsPageProps = {
|
||||||
onBack: () => undefined,
|
onBack: () => undefined,
|
||||||
onDelete: () => undefined,
|
onDelete: () => undefined,
|
||||||
onSubmit: () => undefined,
|
onSubmit: () => undefined,
|
||||||
|
onTokenClose: () => undefined,
|
||||||
onTokenCreate: () => undefined,
|
onTokenCreate: () => undefined,
|
||||||
onTokenDelete: () => undefined,
|
onTokenDelete: () => undefined,
|
||||||
permissions,
|
permissions,
|
||||||
saveButtonBarState: "default",
|
saveButtonBarState: "default",
|
||||||
service
|
service,
|
||||||
|
token: null
|
||||||
};
|
};
|
||||||
storiesOf("Views / Services / Service details", module)
|
storiesOf("Views / Services / Service details", module)
|
||||||
.addDecorator(Decorator)
|
.addDecorator(Decorator)
|
||||||
|
@ -32,4 +34,7 @@ storiesOf("Views / Services / Service details", module)
|
||||||
{...props}
|
{...props}
|
||||||
errors={["name"].map(field => formError(field))}
|
errors={["name"].map(field => formError(field))}
|
||||||
/>
|
/>
|
||||||
|
))
|
||||||
|
.add("default token", () => (
|
||||||
|
<ServiceDetailsPage {...props} token="93B4AF3D7E9FD7C61C4C9B32FF82F" />
|
||||||
));
|
));
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { maybe } from "@saleor/misc";
|
||||||
import { ServiceDetails_serviceAccount } from "@saleor/services/types/ServiceDetails";
|
import { ServiceDetails_serviceAccount } from "@saleor/services/types/ServiceDetails";
|
||||||
import { UserError } from "@saleor/types";
|
import { UserError } from "@saleor/types";
|
||||||
import { PermissionEnum } from "@saleor/types/globalTypes";
|
import { PermissionEnum } from "@saleor/types/globalTypes";
|
||||||
|
import ServiceDefaultToken from "../ServiceDefaultToken";
|
||||||
import ServiceInfo from "../ServiceInfo";
|
import ServiceInfo from "../ServiceInfo";
|
||||||
import ServiceTokens from "../ServiceTokens";
|
import ServiceTokens from "../ServiceTokens";
|
||||||
|
|
||||||
|
@ -32,9 +33,11 @@ export interface ServiceDetailsPageProps {
|
||||||
permissions: ShopInfo_shop_permissions[];
|
permissions: ShopInfo_shop_permissions[];
|
||||||
saveButtonBarState: ConfirmButtonTransitionState;
|
saveButtonBarState: ConfirmButtonTransitionState;
|
||||||
service: ServiceDetails_serviceAccount;
|
service: ServiceDetails_serviceAccount;
|
||||||
|
token: string;
|
||||||
onBack: () => void;
|
onBack: () => void;
|
||||||
onTokenDelete: (id: string) => void;
|
onTokenDelete: (id: string) => void;
|
||||||
onDelete: () => void;
|
onDelete: () => void;
|
||||||
|
onTokenClose: () => void;
|
||||||
onTokenCreate: () => void;
|
onTokenCreate: () => void;
|
||||||
onSubmit: (data: ServiceDetailsPageFormData) => void;
|
onSubmit: (data: ServiceDetailsPageFormData) => void;
|
||||||
}
|
}
|
||||||
|
@ -46,8 +49,10 @@ const ServiceDetailsPage: React.FC<ServiceDetailsPageProps> = props => {
|
||||||
permissions,
|
permissions,
|
||||||
saveButtonBarState,
|
saveButtonBarState,
|
||||||
service,
|
service,
|
||||||
|
token,
|
||||||
onBack,
|
onBack,
|
||||||
onDelete,
|
onDelete,
|
||||||
|
onTokenClose,
|
||||||
onTokenCreate,
|
onTokenCreate,
|
||||||
onTokenDelete,
|
onTokenDelete,
|
||||||
onSubmit
|
onSubmit
|
||||||
|
@ -84,6 +89,15 @@ const ServiceDetailsPage: React.FC<ServiceDetailsPageProps> = props => {
|
||||||
<PageHeader title={maybe(() => service.name)} />
|
<PageHeader title={maybe(() => service.name)} />
|
||||||
<Grid>
|
<Grid>
|
||||||
<div>
|
<div>
|
||||||
|
{token && (
|
||||||
|
<>
|
||||||
|
<ServiceDefaultToken
|
||||||
|
token={token}
|
||||||
|
onTokenClose={onTokenClose}
|
||||||
|
/>
|
||||||
|
<CardSpacer />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<ServiceInfo
|
<ServiceInfo
|
||||||
data={data}
|
data={data}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|
|
@ -37,6 +37,7 @@ const useStyles = makeStyles(
|
||||||
marginRight: theme.spacing.unit
|
marginRight: theme.spacing.unit
|
||||||
},
|
},
|
||||||
copy: {
|
copy: {
|
||||||
|
marginTop: theme.spacing.unit,
|
||||||
position: "relative",
|
position: "relative",
|
||||||
right: theme.spacing.unit
|
right: theme.spacing.unit
|
||||||
},
|
},
|
||||||
|
@ -50,6 +51,10 @@ const useStyles = makeStyles(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function handleCopy(token: string) {
|
||||||
|
navigator.clipboard.writeText(token);
|
||||||
|
}
|
||||||
|
|
||||||
const ServiceTokenCreateDialog: React.FC<
|
const ServiceTokenCreateDialog: React.FC<
|
||||||
ServiceTokenCreateDialogProps
|
ServiceTokenCreateDialogProps
|
||||||
> = props => {
|
> = props => {
|
||||||
|
@ -71,10 +76,7 @@ const ServiceTokenCreateDialog: React.FC<
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} fullWidth maxWidth="sm">
|
<Dialog open={open} fullWidth maxWidth="sm">
|
||||||
<Form initial={{ name: "" }} onSubmit={data => onCreate(data.name)}>
|
<Form initial={{ name: "" }} onSubmit={data => onCreate(data.name)}>
|
||||||
{({ change, data, submit }) => {
|
{({ change, data, submit }) => (
|
||||||
const handleCopy = () => navigator.clipboard.writeText(token);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
<>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
@ -113,14 +115,14 @@ const ServiceTokenCreateDialog: React.FC<
|
||||||
<Button
|
<Button
|
||||||
className={classes.copy}
|
className={classes.copy}
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={handleCopy}
|
onClick={() => handleCopy(token)}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Copy token"
|
defaultMessage="Copy token"
|
||||||
description="button"
|
description="button"
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</Paper>{" "}
|
</Paper>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
@ -151,8 +153,7 @@ const ServiceTokenCreateDialog: React.FC<
|
||||||
)}
|
)}
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</>
|
</>
|
||||||
);
|
)}
|
||||||
}}
|
|
||||||
</Form>
|
</Form>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|
|
@ -23,8 +23,14 @@ const ServiceList: React.FC<RouteComponentProps> = ({ location }) => {
|
||||||
return <ServiceListComponent params={params} />;
|
return <ServiceListComponent params={params} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ServiceDetails: React.FC<RouteComponentProps<{ id: string }>> = ({
|
interface ServiceDetailsProps extends RouteComponentProps<{ id: string }> {
|
||||||
match
|
token: string;
|
||||||
|
onTokenClose: () => void;
|
||||||
|
}
|
||||||
|
const ServiceDetails: React.FC<ServiceDetailsProps> = ({
|
||||||
|
match,
|
||||||
|
token,
|
||||||
|
onTokenClose
|
||||||
}) => {
|
}) => {
|
||||||
const qs = parseQs(location.search.substr(1));
|
const qs = parseQs(location.search.substr(1));
|
||||||
const params: ServiceUrlQueryParams = qs;
|
const params: ServiceUrlQueryParams = qs;
|
||||||
|
@ -33,20 +39,36 @@ const ServiceDetails: React.FC<RouteComponentProps<{ id: string }>> = ({
|
||||||
<ServiceDetailsComponent
|
<ServiceDetailsComponent
|
||||||
id={decodeURIComponent(match.params.id)}
|
id={decodeURIComponent(match.params.id)}
|
||||||
params={params}
|
params={params}
|
||||||
|
token={token}
|
||||||
|
onTokenClose={onTokenClose}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ServiceSection = () => {
|
const ServiceSection = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const [token, setToken] = React.useState<string>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WindowTitle title={intl.formatMessage(sectionNames.serviceAccounts)} />
|
<WindowTitle title={intl.formatMessage(sectionNames.serviceAccounts)} />
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path={serviceListPath} component={ServiceList} />
|
<Route exact path={serviceListPath} component={ServiceList} />
|
||||||
<Route exact path={serviceAddPath} component={ServiceCreate} />
|
<Route
|
||||||
<Route path={servicePath(":id")} component={ServiceDetails} />
|
exact
|
||||||
|
path={serviceAddPath}
|
||||||
|
render={() => <ServiceCreate setToken={setToken} />}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path={servicePath(":id")}
|
||||||
|
render={props => (
|
||||||
|
<ServiceDetails
|
||||||
|
{...props}
|
||||||
|
token={token}
|
||||||
|
onTokenClose={() => setToken(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</Switch>
|
</Switch>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -22,6 +22,7 @@ const serviceCreateMutation = gql`
|
||||||
field
|
field
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
|
authToken
|
||||||
serviceAccount {
|
serviceAccount {
|
||||||
...ServiceFragment
|
...ServiceFragment
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ export interface ServiceCreate_serviceAccountCreate_serviceAccount {
|
||||||
export interface ServiceCreate_serviceAccountCreate {
|
export interface ServiceCreate_serviceAccountCreate {
|
||||||
__typename: "ServiceAccountCreate";
|
__typename: "ServiceAccountCreate";
|
||||||
errors: ServiceCreate_serviceAccountCreate_errors[] | null;
|
errors: ServiceCreate_serviceAccountCreate_errors[] | null;
|
||||||
|
authToken: string | null;
|
||||||
serviceAccount: ServiceCreate_serviceAccountCreate_serviceAccount | null;
|
serviceAccount: ServiceCreate_serviceAccountCreate_serviceAccount | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,10 @@ import ServiceCreatePage, {
|
||||||
} from "../../components/ServiceCreatePage";
|
} from "../../components/ServiceCreatePage";
|
||||||
import { serviceListUrl, serviceUrl } from "../../urls";
|
import { serviceListUrl, serviceUrl } from "../../urls";
|
||||||
|
|
||||||
export const ServiceCreate: React.StatelessComponent = () => {
|
interface ServiceCreateProps {
|
||||||
|
setToken: (token: string) => void;
|
||||||
|
}
|
||||||
|
export const ServiceCreate: React.FC<ServiceCreateProps> = ({ setToken }) => {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
const notify = useNotifier();
|
const notify = useNotifier();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
@ -26,6 +29,7 @@ export const ServiceCreate: React.StatelessComponent = () => {
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
});
|
});
|
||||||
navigate(serviceUrl(data.serviceAccountCreate.serviceAccount.id));
|
navigate(serviceUrl(data.serviceAccountCreate.serviceAccount.id));
|
||||||
|
setToken(data.serviceAccountCreate.authToken);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,17 +34,23 @@ import {
|
||||||
interface OrderListProps {
|
interface OrderListProps {
|
||||||
id: string;
|
id: string;
|
||||||
params: ServiceUrlQueryParams;
|
params: ServiceUrlQueryParams;
|
||||||
|
token: string;
|
||||||
|
onTokenClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ServiceDetails: React.StatelessComponent<OrderListProps> = ({
|
export const ServiceDetails: React.StatelessComponent<OrderListProps> = ({
|
||||||
id,
|
id,
|
||||||
params
|
params,
|
||||||
|
token,
|
||||||
|
onTokenClose
|
||||||
}) => {
|
}) => {
|
||||||
const navigate = useNavigator();
|
const navigate = useNavigator();
|
||||||
const notify = useNotifier();
|
const notify = useNotifier();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const shop = useShop();
|
const shop = useShop();
|
||||||
|
|
||||||
|
React.useEffect(() => onTokenClose, []);
|
||||||
|
|
||||||
const closeModal = () =>
|
const closeModal = () =>
|
||||||
navigate(
|
navigate(
|
||||||
serviceUrl(id, {
|
serviceUrl(id, {
|
||||||
|
@ -203,9 +209,11 @@ export const ServiceDetails: React.StatelessComponent<OrderListProps> = ({
|
||||||
<ServiceDetailsPage
|
<ServiceDetailsPage
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
errors={[]}
|
errors={[]}
|
||||||
|
token={token}
|
||||||
onBack={handleBack}
|
onBack={handleBack}
|
||||||
onDelete={() => openModal("remove")}
|
onDelete={() => openModal("remove")}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
|
onTokenClose={onTokenClose}
|
||||||
onTokenCreate={() => openModal("create-token")}
|
onTokenCreate={() => openModal("create-token")}
|
||||||
onTokenDelete={id =>
|
onTokenDelete={id =>
|
||||||
openModal("remove-token", id)
|
openModal("remove-token", id)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import Card from "@material-ui/core/Card";
|
||||||
import { createMuiTheme, Theme } from "@material-ui/core/styles";
|
import { createMuiTheme, Theme } from "@material-ui/core/styles";
|
||||||
import { darken, fade } from "@material-ui/core/styles/colorManipulator";
|
import { darken, fade } from "@material-ui/core/styles/colorManipulator";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
|
@ -84,7 +85,6 @@ export default (colors: IThemeColors): Theme =>
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
borderStyle: "solid",
|
borderStyle: "solid",
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
boxShadow: "none",
|
|
||||||
overflow: "visible"
|
overflow: "visible"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -540,3 +540,8 @@ TextField.defaultProps = {
|
||||||
...TextField.defaultProps,
|
...TextField.defaultProps,
|
||||||
variant: "outlined"
|
variant: "outlined"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Card.defaultProps = {
|
||||||
|
...Card.defaultProps,
|
||||||
|
elevation: 0
|
||||||
|
};
|
||||||
|
|
|
@ -321,6 +321,8 @@ export interface AttributeFilterInput {
|
||||||
availableInGrid?: boolean | null;
|
availableInGrid?: boolean | null;
|
||||||
search?: string | null;
|
search?: string | null;
|
||||||
ids?: (string | null)[] | null;
|
ids?: (string | null)[] | null;
|
||||||
|
inCollection?: string | null;
|
||||||
|
inCategory?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AttributeInput {
|
export interface AttributeInput {
|
||||||
|
|
Loading…
Reference in a new issue