Skip to content

Commit

Permalink
Update footy-report extension
Browse files Browse the repository at this point in the history
- Merge pull request raycast#32 from thuoe/next
- Merge pull request raycast#31 from thuoe/feature/thu-35-api-test-command-validate-sportmonks-endpoint
- feat: validate endpoint before submit
- Merge pull request raycast#30 from thuoe/main
  • Loading branch information
thuoe committed Jan 11, 2024
1 parent a823d18 commit a3c5e6e
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions extensions/footy-report/src/test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Action, ActionPanel, Form, Icon, useNavigation } from "@raycast/api";
import {
Action,
ActionPanel,
Form,
Icon,
Toast,
showToast,
useNavigation,
} from "@raycast/api";
import { showFailureToast } from "@raycast/utils";
import axios from "axios";
import { useState } from "react";
Expand All @@ -8,12 +16,13 @@ import APIResult from "@src/components/APIResult";
export default () => {
const { push } = useNavigation();
const apiKey = useAPIKey();
const [nameError, setNameError] = useState<string | undefined>();
const dropNameErrorIfNeeded = () => {
if (nameError && nameError.length > 0) {
setNameError(undefined);
const [endpointError, setEndpointError] = useState<string | undefined>();
const dropEndpointErrorIfNeeded = () => {
if (endpointError && endpointError.length > 0) {
setEndpointError(undefined);
}
};

return (
<Form
navigationTitle="Test SportMonks API"
Expand All @@ -30,6 +39,11 @@ export default () => {
url,
headers: { Authorization: apiKey },
});
await showToast({
title: "Success!",
message: "Rendering Response...",
style: Toast.Style.Success,
});
push(<APIResult response={response} url={url} />);
} catch (error) {
showFailureToast(error);
Expand All @@ -44,16 +58,18 @@ export default () => {
text="To test the validity of your access token, make an API call using a SportMonks API endpoint (V3). For documentation on endpoints please visit https://docs.sportmonks.com/football/welcome/getting-started"
/>
<Form.TextField
autoFocus
id="url"
title="URL"
placeholder="https://api.sportmonks.com/v3/some_path_here"
error={nameError}
onChange={dropNameErrorIfNeeded}
onBlur={(event) => {
if (event.target.value?.length === 0) {
setNameError("URL should not be empty!");
error={endpointError}
onChange={(endpoint) => {
const endpointRegex =
/^https:\/\/api\.sportmonks\.com\/v3\/football\/.*/g;
if (!endpoint.match(endpointRegex)) {
setEndpointError("SportMonks URL not valid!");
} else {
dropNameErrorIfNeeded();
dropEndpointErrorIfNeeded();
}
}}
/>
Expand Down

0 comments on commit a3c5e6e

Please sign in to comment.