Fix types
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import type { FC } from "react";
|
import type { FC } from "react";
|
||||||
import { CastesLinks } from "./CastesLinks";
|
import { CastesLinks } from "./CastesLinks";
|
||||||
import { LocalLinks } from "./LocalLinks";
|
import { LocalLinks } from "./LocalLinks";
|
||||||
|
import type { LinkInterface } from "./types";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const links = [
|
const links = [
|
||||||
@@ -66,12 +67,6 @@ export const LinkGroup: FC<LinkGroupProps> = ({ title, links }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface LinkInterface {
|
|
||||||
name: string;
|
|
||||||
link: string;
|
|
||||||
icon?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LinkProps {
|
interface LinkProps {
|
||||||
link: LinkInterface;
|
link: LinkInterface;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { LinkGroup } from "./App";
|
import { LinkGroup } from "./App";
|
||||||
|
import type { ApiError, LinkInterface } from "./types";
|
||||||
|
|
||||||
export const CastesLinks = () => {
|
export const CastesLinks = () => {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [links, setLinks] = useState([]);
|
const [links, setLinks] = useState<LinkInterface[]>([]);
|
||||||
const castesLinks = [
|
const castesLinks = [
|
||||||
{ name: "GPAO", link: "http://gpao.lan" },
|
{ name: "GPAO", link: "http://gpao.lan" },
|
||||||
{ name: "Penpot", link: "https://penpot.castes-industrie.fr" },
|
{ name: "Penpot", link: "https://penpot.castes-industrie.fr" },
|
||||||
@@ -23,9 +24,13 @@ export const CastesLinks = () => {
|
|||||||
setLinks(castesLinks);
|
setLinks(castesLinks);
|
||||||
}
|
}
|
||||||
console.log("link", res);
|
console.log("link", res);
|
||||||
} catch (error: Error | NetworkError | unknown) {
|
} catch (error: Error | ApiError | unknown) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
setError(error.response?.data.message || error.message);
|
if (error instanceof Error) {
|
||||||
|
console.error(error.message);
|
||||||
|
} else {
|
||||||
|
setError((error as ApiError).error);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/types.ts
Normal file
16
src/types.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
export interface ApiError {
|
||||||
|
error: string;
|
||||||
|
status?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Link {
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
icon?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LinkInterface {
|
||||||
|
name: string;
|
||||||
|
link: string;
|
||||||
|
icon?: string;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user