This commit is contained in:
dominik-zeglen 2019-10-04 12:57:40 +02:00
parent 9d5958b32c
commit ec91b08514
6 changed files with 50 additions and 15 deletions

View file

@ -12,12 +12,14 @@ interface StaffStatusProps {
isActive: boolean; isActive: boolean;
}; };
disabled: boolean; disabled: boolean;
label: React.ReactNode;
onChange: (event: React.ChangeEvent<any>) => void; onChange: (event: React.ChangeEvent<any>) => void;
} }
const StaffStatus: React.StatelessComponent<StaffStatusProps> = ({ const StaffStatus: React.StatelessComponent<StaffStatusProps> = ({
data, data,
disabled, disabled,
label,
onChange onChange
}) => { }) => {
const intl = useIntl(); const intl = useIntl();
@ -37,10 +39,7 @@ const StaffStatus: React.StatelessComponent<StaffStatusProps> = ({
<ControlledCheckbox <ControlledCheckbox
checked={data.isActive} checked={data.isActive}
disabled={disabled} disabled={disabled}
label={intl.formatMessage({ label={label}
defaultMessage: "User is active",
description: "checkbox label"
})}
name="isActive" name="isActive"
onChange={onChange} onChange={onChange}
/> />

View file

@ -8,11 +8,14 @@ import { fade } from "@material-ui/core/styles/colorManipulator";
import Typography from "@material-ui/core/Typography"; import Typography from "@material-ui/core/Typography";
import CloseIcon from "@material-ui/icons/Close"; import CloseIcon from "@material-ui/icons/Close";
import { makeStyles } from "@material-ui/styles"; import { makeStyles } from "@material-ui/styles";
import Link from "@saleor/components/Link";
import React from "react"; import React from "react";
import { FormattedMessage } from "react-intl"; import { FormattedMessage } from "react-intl";
export interface ServiceDefaultTokenProps { export interface ServiceDefaultTokenProps {
apiUri: string;
token: string; token: string;
onApiUriClick: () => void;
onTokenClose: () => void; onTokenClose: () => void;
} }
@ -28,6 +31,12 @@ const useStyles = makeStyles(
right: -theme.spacing.unit, right: -theme.spacing.unit,
top: -theme.spacing.unit top: -theme.spacing.unit
}, },
content: {
display: "grid",
gridColumnGap: theme.spacing.unit * 3 + "px",
gridTemplateColumns: "1fr 60px",
marginBottom: theme.spacing.unit * 3
},
copy: { copy: {
marginTop: theme.spacing.unit, marginTop: theme.spacing.unit,
position: "relative", position: "relative",
@ -39,12 +48,6 @@ const useStyles = makeStyles(
}, },
root: { root: {
boxShadow: "0px 5px 10px rgba(0, 0, 0, 0.05)" 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
} }
}), }),
{ {
@ -57,16 +60,30 @@ function handleCopy(token: string) {
} }
const ServiceDefaultToken: React.FC<ServiceDefaultTokenProps> = props => { const ServiceDefaultToken: React.FC<ServiceDefaultTokenProps> = props => {
const { token, onTokenClose } = props; const { apiUri, token, onApiUriClick, onTokenClose } = props;
const classes = useStyles(props); const classes = useStyles(props);
return ( return (
<Card className={classes.root}> <Card className={classes.root}>
<CardContent> <CardContent>
<div className={classes.text}> <div className={classes.content}>
<Typography> <div>
<FormattedMessage defaultMessage="Weve created your default token. Make sure to copy your new personal access token now. You wont be able to see it again." /> <Typography>
</Typography> <FormattedMessage defaultMessage="Weve created your default token. Make sure to copy your new personal access token now. You wont be able to see it again." />
</Typography>
<Typography>
<FormattedMessage
defaultMessage="This token gives you access to your shop's API, which you'll find here: {url}"
values={{
url: (
<Link href={apiUri} onClick={onApiUriClick}>
{apiUri}
</Link>
)
}}
/>
</Typography>
</div>
<div className={classes.closeContainer}> <div className={classes.closeContainer}>
<IconButton onClick={onTokenClose}> <IconButton onClick={onTokenClose}>
<CloseIcon /> <CloseIcon />

View file

@ -10,8 +10,10 @@ import ServiceDetailsPage, {
} from "./ServiceDetailsPage"; } from "./ServiceDetailsPage";
const props: ServiceDetailsPageProps = { const props: ServiceDetailsPageProps = {
apiUri: "https://example.com/graphql/",
disabled: false, disabled: false,
errors: [], errors: [],
onApiUriClick: () => undefined,
onBack: () => undefined, onBack: () => undefined,
onDelete: () => undefined, onDelete: () => undefined,
onSubmit: () => undefined, onSubmit: () => undefined,

View file

@ -28,12 +28,14 @@ export interface ServiceDetailsPageFormData {
permissions: PermissionEnum[]; permissions: PermissionEnum[];
} }
export interface ServiceDetailsPageProps { export interface ServiceDetailsPageProps {
apiUri: string;
disabled: boolean; disabled: boolean;
errors: UserError[]; errors: UserError[];
permissions: ShopInfo_shop_permissions[]; permissions: ShopInfo_shop_permissions[];
saveButtonBarState: ConfirmButtonTransitionState; saveButtonBarState: ConfirmButtonTransitionState;
service: ServiceDetails_serviceAccount; service: ServiceDetails_serviceAccount;
token: string; token: string;
onApiUriClick: () => void;
onBack: () => void; onBack: () => void;
onTokenDelete: (id: string) => void; onTokenDelete: (id: string) => void;
onDelete: () => void; onDelete: () => void;
@ -44,12 +46,14 @@ export interface ServiceDetailsPageProps {
const ServiceDetailsPage: React.FC<ServiceDetailsPageProps> = props => { const ServiceDetailsPage: React.FC<ServiceDetailsPageProps> = props => {
const { const {
apiUri,
disabled, disabled,
errors: formErrors, errors: formErrors,
permissions, permissions,
saveButtonBarState, saveButtonBarState,
service, service,
token, token,
onApiUriClick,
onBack, onBack,
onDelete, onDelete,
onTokenClose, onTokenClose,
@ -92,7 +96,9 @@ const ServiceDetailsPage: React.FC<ServiceDetailsPageProps> = props => {
{token && ( {token && (
<> <>
<ServiceDefaultToken <ServiceDefaultToken
apiUri={apiUri}
token={token} token={token}
onApiUriClick={onApiUriClick}
onTokenClose={onTokenClose} onTokenClose={onTokenClose}
/> />
<CardSpacer /> <CardSpacer />
@ -122,6 +128,10 @@ const ServiceDetailsPage: React.FC<ServiceDetailsPageProps> = props => {
<AccountStatus <AccountStatus
data={data} data={data}
disabled={disabled} disabled={disabled}
label={intl.formatMessage({
defaultMessage: "Service account is active",
description: "checkbox label"
})}
onChange={change} onChange={change}
/> />
</div> </div>

View file

@ -2,6 +2,7 @@ import React from "react";
import { useIntl } from "react-intl"; import { useIntl } from "react-intl";
import { WindowTitle } from "@saleor/components/WindowTitle"; import { WindowTitle } from "@saleor/components/WindowTitle";
import { API_URI } from "@saleor/config";
import useNavigator from "@saleor/hooks/useNavigator"; import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier"; import useNotifier from "@saleor/hooks/useNotifier";
import useShop from "@saleor/hooks/useShop"; import useShop from "@saleor/hooks/useShop";
@ -207,9 +208,11 @@ export const ServiceDetails: React.StatelessComponent<OrderListProps> = ({
title={maybe(() => data.serviceAccount.name)} title={maybe(() => data.serviceAccount.name)}
/> />
<ServiceDetailsPage <ServiceDetailsPage
apiUri={API_URI}
disabled={loading} disabled={loading}
errors={[]} errors={[]}
token={token} token={token}
onApiUriClick={() => open(API_URI, "blank")}
onBack={handleBack} onBack={handleBack}
onDelete={() => openModal("remove")} onDelete={() => openModal("remove")}
onSubmit={handleSubmit} onSubmit={handleSubmit}

View file

@ -107,6 +107,10 @@ const StaffDetailsPage: React.StatelessComponent<StaffDetailsPageProps> = ({
<AccountStatus <AccountStatus
data={data} data={data}
disabled={disabled} disabled={disabled}
label={intl.formatMessage({
defaultMessage: "User is active",
description: "checkbox label"
})}
onChange={change} onChange={change}
/> />
</div> </div>