diff --git a/frontend/src/components/ChangeAPI.tsx b/frontend/src/components/ChangeAPI.tsx
new file mode 100644
index 0000000..2e9b977
--- /dev/null
+++ b/frontend/src/components/ChangeAPI.tsx
@@ -0,0 +1,34 @@
+import React, { useState } from "react";
+import { changeAPIcookie } from "../utils/changeAPIcookie";
+
+interface Props {
+ currentAPIKey: string;
+}
+
+function ChangeAPI({ currentAPIKey }: Props) {
+ const [apiKey, setApiKey] = useState(currentAPIKey);
+
+ return (
+
+
Change API Key
+
Update your API key to fetch weather data.
+
+
+ );
+}
+
+export default ChangeAPI;
diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx
index 00ef2e2..0d9a155 100644
--- a/frontend/src/components/Header.tsx
+++ b/frontend/src/components/Header.tsx
@@ -1,19 +1,20 @@
import React from "react";
+import ChangeAPI from "./ChangeAPI";
+import { useState } from "react";
import Cookies from "js-cookie";
const Header: React.FC = () => {
- const setApiKey = () => {
- const apiKey = prompt("Enter your API key:");
- if (apiKey) {
- Cookies.set("apiKey", apiKey);
- }
- console.log(Cookies.get("apiKey"));
- };
+ const [apiCard, setApiCard] = useState(false);
+ const apiKey = Cookies.get("apiKey") || "";
+
return (
-
- Weather App
-
-
+ <>
+
+ Weather App
+
+
+ {apiCard && }
+ >
);
};
diff --git a/frontend/src/utils/changeAPIcookie.ts b/frontend/src/utils/changeAPIcookie.ts
new file mode 100644
index 0000000..6e682da
--- /dev/null
+++ b/frontend/src/utils/changeAPIcookie.ts
@@ -0,0 +1,7 @@
+import Cookies from "js-cookie";
+import { myToast } from "./toastify";
+
+export const changeAPIcookie = (newApiKey: string) => {
+ Cookies.set("apiKey", newApiKey);
+ myToast("API key updated successfully!", "success");
+};