saleor-dashboard/src/new-apps/components/InstallWithManifestFormButton/InstallWithManifestFormButton.tsx
Dawid 1621feb691
Apps marketplace (#2850)
* Add new Apps List

* Update apps routing

* Add marketplace apps list

* Update apps urls

* Update app list style

* Add installed apps section

* Update apps sections and connect actions with mutations

* Add latest missing buttons and labels to installed apps list

* Update installed apps list

* Update installed apps list

* Add tests and marketplace error handling

* Update environment configuration

* Update GitHub actions env configuration

* Refactor AppListCard component

* Test InstallWithManifestFormButton

* Test AppListCard

* Extract InstalledAppListRow with tests

* Update GitHub actions env configuration

* Tests of apps dialogs

* Update GitHub actions env configuration

* Update messages

* Update GitHub actions env configuration

* Quote untrusted GitHub actions variables

* Change useFetch to useMarketplaceApps and add tests

* Fix strict null check errors

* Refactor apps details components

* Add strict null checks for /new-apps/ components
2023-01-10 11:04:30 +01:00

74 lines
2 KiB
TypeScript

import { TextField } from "@material-ui/core";
import { Button } from "@saleor/components/Button";
import { buttonMessages } from "@saleor/intl";
import { appsMessages } from "@saleor/new-apps/messages";
import React, { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { messages } from "./messages";
import { useStyles } from "./styles";
interface Props {
onSubmitted(manifestUrl: string): void;
}
export const InstallWithManifestFormButton: React.FC<Props> = ({
onSubmitted,
}) => {
const styles = useStyles();
const intl = useIntl();
const [inputOpened, setInputOpened] = useState(false);
const handleFormSubmit: React.FormEventHandler<HTMLFormElement> = e => {
e.preventDefault();
const form = new FormData(e.currentTarget);
const inputValue = form.get("manifest-url") as string;
try {
new URL(inputValue);
onSubmitted(inputValue);
} catch (e) {
console.error("Invalid URL from input. Should be validated by browser");
}
};
if (inputOpened) {
return (
<form onSubmit={handleFormSubmit}>
<TextField
data-test-id="manifest-url-input"
required
type="url"
name="manifest-url"
label={intl.formatMessage(appsMessages.appManifestUrl)}
defaultValue=""
helperText={intl.formatMessage(messages.appManifestUrlHint)}
/>
<Button
size="medium"
type="submit"
className={styles.installButton}
variant="primary"
data-test-id="install-app-from-manifest"
>
<FormattedMessage {...buttonMessages.install} />
</Button>
</form>
);
}
return (
<Button
variant="secondary"
data-test-id="add-app-from-manifest"
onClick={() => setInputOpened(true)}
>
<FormattedMessage {...messages.installExternalApp} />
</Button>
);
};
InstallWithManifestFormButton.displayName = "InstallWithManifestFormButton";
export default InstallWithManifestFormButton;