Provider configurations UI fixes (#374)
* Provider configurations UI fixes * Create .changeset/nice-donkeys-stare.md
This commit is contained in:
parent
7ff2d7cfa7
commit
246b94360e
9 changed files with 4016 additions and 4531 deletions
5
.changeset/nice-donkeys-stare.md
Normal file
5
.changeset/nice-donkeys-stare.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"saleor-app-cms": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Provider configurations UI fixes
|
|
@ -22,7 +22,7 @@
|
||||||
"@material-ui/lab": "4.0.0-alpha.61",
|
"@material-ui/lab": "4.0.0-alpha.61",
|
||||||
"@saleor/app-sdk": "0.37.1",
|
"@saleor/app-sdk": "0.37.1",
|
||||||
"@saleor/apps-shared": "workspace:*",
|
"@saleor/apps-shared": "workspace:*",
|
||||||
"@saleor/macaw-ui": "^0.6.7",
|
"@saleor/macaw-ui": "^0.7.2",
|
||||||
"@sentry/nextjs": "^7.43.0",
|
"@sentry/nextjs": "^7.43.0",
|
||||||
"@urql/exchange-auth": "^1.0.0",
|
"@urql/exchange-auth": "^1.0.0",
|
||||||
"clsx": "^1.2.1",
|
"clsx": "^1.2.1",
|
||||||
|
|
|
@ -137,7 +137,7 @@ export const ChannelConfigurationForm = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListItem key={providerInstance.name} className={styles.item}>
|
<ListItem key={providerInstance.id} className={styles.item}>
|
||||||
<ListItemCell className={styles.itemCell}>
|
<ListItemCell className={styles.itemCell}>
|
||||||
<ProviderIcon providerName={providerInstance.providerName} />
|
<ProviderIcon providerName={providerInstance.providerName} />
|
||||||
{providerInstance.name}
|
{providerInstance.name}
|
||||||
|
|
|
@ -1,12 +1,31 @@
|
||||||
|
import { makeStyles } from "@saleor/macaw-ui";
|
||||||
import { getProviderByName } from "../../providers/config";
|
import { getProviderByName } from "../../providers/config";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
import clsx from "clsx";
|
||||||
|
|
||||||
interface ProviderIconProps {
|
interface ProviderIconProps {
|
||||||
providerName: string;
|
providerName: string;
|
||||||
|
small?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProviderIcon = ({ providerName }: ProviderIconProps) => {
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
small: {
|
||||||
|
width: theme.spacing(2.5),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const ProviderIcon = ({ providerName, small = false }: ProviderIconProps) => {
|
||||||
|
const styles = useStyles();
|
||||||
|
|
||||||
const provider = getProviderByName(providerName);
|
const provider = getProviderByName(providerName);
|
||||||
|
|
||||||
return provider ? <Image src={provider.iconSrc} alt={`${provider.label} icon`} /> : null;
|
return provider ? (
|
||||||
|
<Image
|
||||||
|
src={provider.iconSrc}
|
||||||
|
alt={`${provider.label} icon`}
|
||||||
|
className={clsx({
|
||||||
|
[styles.small]: small,
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
) : null;
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,8 +57,6 @@ export const ProviderInstanceConfigurationForm = <TProvider extends CMSProviderS
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("form", providerInstance);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
resetField("providerName" as Path<ProvidersSchema[TProvider]>, {
|
resetField("providerName" as Path<ProvidersSchema[TProvider]>, {
|
||||||
defaultValue: provider.name,
|
defaultValue: provider.name,
|
||||||
|
@ -89,11 +87,6 @@ export const ProviderInstanceConfigurationForm = <TProvider extends CMSProviderS
|
||||||
Error validating form
|
Error validating form
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
<input
|
|
||||||
type="hidden"
|
|
||||||
{...register("id" as Path<ProvidersSchema[TProvider]>)}
|
|
||||||
value={providerInstance?.id}
|
|
||||||
/>
|
|
||||||
<input
|
<input
|
||||||
type="hidden"
|
type="hidden"
|
||||||
{...register("providerName" as Path<ProvidersSchema[TProvider]>)}
|
{...register("providerName" as Path<ProvidersSchema[TProvider]>)}
|
||||||
|
@ -147,6 +140,21 @@ export const ProviderInstanceConfigurationForm = <TProvider extends CMSProviderS
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
))}
|
))}
|
||||||
|
{providerInstance ? (
|
||||||
|
<Grid item xs={12}>
|
||||||
|
<TextField
|
||||||
|
{...register("id" as Path<ProvidersSchema[TProvider]>)}
|
||||||
|
label="Configuration id"
|
||||||
|
type="text"
|
||||||
|
name="id"
|
||||||
|
fullWidth
|
||||||
|
helperText="Automatically generated unique identifier for the configuration instance."
|
||||||
|
disabled={true}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
) : (
|
||||||
|
<input type="hidden" {...register("id" as Path<ProvidersSchema[TProvider]>)} />
|
||||||
|
)}
|
||||||
<Grid item xs={12} className={providerInstance ? styles.footerComplex : styles.footer}>
|
<Grid item xs={12} className={providerInstance ? styles.footerComplex : styles.footer}>
|
||||||
{providerInstance && (
|
{providerInstance && (
|
||||||
<Button variant="secondary" disabled={loading} onClick={() => onDelete(getValues())}>
|
<Button variant="secondary" disabled={loading} onClick={() => onDelete(getValues())}>
|
||||||
|
|
|
@ -199,7 +199,7 @@ export const ProviderInstanceConfiguration = ({
|
||||||
<br />
|
<br />
|
||||||
<ProviderInstanceConfigurationForm
|
<ProviderInstanceConfigurationForm
|
||||||
provider={selectedProvider}
|
provider={selectedProvider}
|
||||||
providerInstance={activeProviderInstance}
|
providerInstance={!newProviderInstance ? activeProviderInstance : null}
|
||||||
loading={loading.saving}
|
loading={loading.saving}
|
||||||
onSubmit={saveProviderInstance}
|
onSubmit={saveProviderInstance}
|
||||||
onDelete={deleteProviderInstance}
|
onDelete={deleteProviderInstance}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import { SingleProviderSchema } from "../../../lib/cms/config";
|
||||||
import { AppPaper } from "../../ui/app-paper";
|
import { AppPaper } from "../../ui/app-paper";
|
||||||
|
|
||||||
import { ProvidersErrors, ProvidersLoading } from "./types";
|
import { ProvidersErrors, ProvidersLoading } from "./types";
|
||||||
|
import { ProviderIcon } from "./provider-icon";
|
||||||
|
import { makeStyles } from "@saleor/macaw-ui";
|
||||||
|
|
||||||
const ProviderInstancesListSkeleton = () => {
|
const ProviderInstancesListSkeleton = () => {
|
||||||
return (
|
return (
|
||||||
|
@ -23,6 +25,14 @@ const ProviderInstancesListSkeleton = () => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
menuItem: {
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: theme.spacing(2),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
interface ProviderInstancesListProps {
|
interface ProviderInstancesListProps {
|
||||||
providerInstances: SingleProviderSchema[];
|
providerInstances: SingleProviderSchema[];
|
||||||
activeProviderInstance?: SingleProviderSchema | null;
|
activeProviderInstance?: SingleProviderSchema | null;
|
||||||
|
@ -42,6 +52,8 @@ export const ProviderInstancesSelect = ({
|
||||||
loading,
|
loading,
|
||||||
errors,
|
errors,
|
||||||
}: ProviderInstancesListProps) => {
|
}: ProviderInstancesListProps) => {
|
||||||
|
const styles = useStyles();
|
||||||
|
|
||||||
const handleSetActiveProviderInstance = (providerInstance: SingleProviderSchema) => {
|
const handleSetActiveProviderInstance = (providerInstance: SingleProviderSchema) => {
|
||||||
setActiveProviderInstance(providerInstance);
|
setActiveProviderInstance(providerInstance);
|
||||||
};
|
};
|
||||||
|
@ -73,7 +85,10 @@ export const ProviderInstancesSelect = ({
|
||||||
>
|
>
|
||||||
{providerInstances.map((p) => (
|
{providerInstances.map((p) => (
|
||||||
<MenuItem key={p.id} value={p.id}>
|
<MenuItem key={p.id} value={p.id}>
|
||||||
{p.name}
|
<div className={styles.menuItem}>
|
||||||
|
<ProviderIcon providerName={p.providerName} small />
|
||||||
|
{p.name}
|
||||||
|
</div>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
|
|
@ -26,7 +26,7 @@ export const ProviderInstances = () => {
|
||||||
const [newProviderInstance, setNewProviderInstance] = useState<SingleProviderSchema | null>(null);
|
const [newProviderInstance, setNewProviderInstance] = useState<SingleProviderSchema | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (providerInstances.length) {
|
if (providerInstances.length && !activeProviderInstanceId) {
|
||||||
setActiveProviderInstanceId(providerInstances[0].id);
|
setActiveProviderInstanceId(providerInstances[0].id);
|
||||||
}
|
}
|
||||||
}, [providerInstances]);
|
}, [providerInstances]);
|
||||||
|
|
8472
pnpm-lock.yaml
8472
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue