Skip to content

Commit

Permalink
Design Review: Use Alert for Deploy error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gianlucaparadise committed Jul 5, 2022
1 parent 2730623 commit e49a2fc
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 100 deletions.
61 changes: 61 additions & 0 deletions admin/src/components/DeployButton/ErrorUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @typedef {import("./typedefs").ErrorStateType} ErrorStateType
* @typedef {import('../../components/Notifications/typedefs').NotificationConfig} NotificationConfig
*/

/**
* @param {ErrorStateType} type
* @returns {NotificationConfig} Error Notification
*/
export const getErrorNotification = (type) => {
/** @type {NotificationConfig} */
const baseConfig = {
id: type,
blockTransition: true,
type: "warning",
};

switch (type) {
case "MISSING_CONFIG_OBJECT":
return {
...baseConfig,
message: { id: "deploy-error-message.missing-config-object" },
};

case "MISSING_CONFIG_VARIABLE":
return {
...baseConfig,
message: { id: "deploy-error-message.missing-config-variable.intro" },
link: {
label: {
id: "deploy-error-message.missing-config-variable.link-text",
},
url: "/settings/vercel-deploy",
},
};

case "ERROR_AVAILABILITY":
return {
...baseConfig,
message: { id: "deploy-error-message.error-availability" },
};

case "ERROR_FORBIDDEN":
return {
...baseConfig,
message: { id: "deploy-error-message.error-forbidden" },
};

case "ERROR_DEPLOY":
return {
...baseConfig,
message: { id: "deploy-error-message.error-deploy" },
};

default:
return {
...baseConfig,
message: { id: "deploy-error-message.default" },
};
}
};
26 changes: 16 additions & 10 deletions admin/src/components/DeployButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@
*
*/

import React, { useState } from "react";
import React, { useState, useEffect } from "react";

import { useNotification } from "@strapi/helper-plugin";
import { Button } from "@strapi/design-system/Button";
import { Loader } from "@strapi/design-system/Loader";
import Plus from "@strapi/icons/Plus";

import SymmetricBox from "../../components/SymmetricBox";
import DeployErrorMessage from "../../components/DeployErrorMessage";
import { runDeploy } from "../../utils/api";
import FormattedMessage from "../FormattedMessage";
import { getErrorNotification } from "./ErrorUtils";
import { runDeploy } from "../../utils/api";
import { useFormattedMessage } from "../../hooks/useFormattedMessage";

/**
* @typedef {import('./typedefs').Props} Props
* @typedef {import('./typedefs').FeatureAvailability} FeatureAvailability
* @typedef {import('./typedefs').ApiErrorType} ApiErrorType
* @typedef {import('../../components/DeployErrorMessage/typedefs').ErrorStateType} DeployErrorStateType
* @typedef {import('./typedefs').ErrorStateType} DeployErrorStateType
* @typedef {import('../../components/Notifications/typedefs').NotificationConfig} NotificationConfig
*/

/**
Expand Down Expand Up @@ -59,6 +61,8 @@ const DeployButton = ({
runDeployAvailability,
onDeployed,
}) => {
/** @type {(config: NotificationConfig) => void} */
const toggleNotification = useNotification();
const labelLoader = useFormattedMessage("deploy-button.loader");

const [isLoading, setIsLoading] = useState(false);
Expand All @@ -70,7 +74,14 @@ const DeployButton = ({
availabilityApiError,
runDeployAvailability
);
const hasDeployedSuccessfully = deployErrorState === "AVAILABLE";

useEffect(() => {
const hasDeployedSuccessfully = deployErrorState === "AVAILABLE";
if (!hasDeployedSuccessfully) {
const notification = getErrorNotification(deployErrorState);
toggleNotification(notification);
}
}, [deployErrorState, toggleNotification, getErrorNotification]);

const runDeployHandler = async () => {
try {
Expand All @@ -94,11 +105,6 @@ const DeployButton = ({
<Loader small>{labelLoader}</Loader>
</SymmetricBox>
)}
{!hasDeployedSuccessfully && (
<SymmetricBox paddingHorizontal={1}>
<DeployErrorMessage type={deployErrorState} />
</SymmetricBox>
)}
<SymmetricBox paddingHorizontal={4}>
<Button onClick={runDeployHandler} disabled={!canDeploy || isLoading}>
<div style={{ display: "flex", alignItems: "center" }}>
Expand Down
5 changes: 5 additions & 0 deletions admin/src/components/DeployButton/typedefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* @typedef {import('../../../../types/typedefs').ApiErrorType} ApiErrorType
*/

/**
* Describe the type of error state to display
* @typedef {(FeatureAvailability|"ERROR_AVAILABILITY"|"ERROR_DEPLOY"|"ERROR_FORBIDDEN")} ErrorStateType
*/

/**
* Callback to notify that the list of deployments has been fetched
* @callback Deployed
Expand Down
74 changes: 0 additions & 74 deletions admin/src/components/DeployErrorMessage/index.js

This file was deleted.

16 changes: 0 additions & 16 deletions admin/src/components/DeployErrorMessage/typedefs.js

This file was deleted.

0 comments on commit e49a2fc

Please sign in to comment.