diff --git a/src/components/ResourcePhoto.tsx b/src/components/ResourcePhoto.tsx
index 379f8ab..df56ba2 100644
--- a/src/components/ResourcePhoto.tsx
+++ b/src/components/ResourcePhoto.tsx
@@ -46,7 +46,7 @@ export const ResourcePhoto = (input: ResourcePhotoProps) => {
return (
diff --git a/src/components/admin/resources/form.tsx b/src/components/admin/resources/form.tsx
index 8d60d1a..4efd041 100644
--- a/src/components/admin/resources/form.tsx
+++ b/src/components/admin/resources/form.tsx
@@ -41,6 +41,7 @@ import Modal from "react-modal";
import { type RouterInputs } from "~/utils/api";
import { PlatformLinkButton } from "~/pages/resources/[id]";
import { ResourcePhoto } from "~/components/ResourcePhoto";
+import Image from "next/image";
// Required for accessibility
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
@@ -90,10 +91,12 @@ const SelectImageInput = ({
src={resource?.icon}
/>
) : (
-
)}
diff --git a/src/pages/resources/[id]/edit.tsx b/src/pages/resources/[id]/edit.tsx
index 28aa5c3..e5f40f7 100644
--- a/src/pages/resources/[id]/edit.tsx
+++ b/src/pages/resources/[id]/edit.tsx
@@ -17,6 +17,7 @@ const EditResourcePage = () => {
const router = useRouter();
const id = router.query["id"]?.toString() ?? "";
+ // TODO: Maybe useWait id before querying
const { data: resource } = api.auditoryResource.byId.useQuery({ id });
const [updateIconFile, setIconFile] = useState(undefined);
@@ -26,37 +27,44 @@ const EditResourcePage = () => {
});
const { mutate } = api.auditoryResource.update.useMutation({
- onSuccess: (_data) => {
+ onSuccess: async (_data) => {
+ if (!resource) {
+ setServerError("An unexpected error has occured");
+ return;
+ }
+
setServerError(undefined);
+
+ if (updateIconFile) {
+ const data = new FormData();
+ data.append("photo", updateIconFile);
+
+ if (!resource?.id) {
+ throw Error("Resource data missing for photo to upload");
+ }
+
+ const uploadResponse = await fetch(
+ `/api/resources/photo/${resource.id}`,
+ {
+ method: "POST",
+ body: data,
+ }
+ );
+
+ if (uploadResponse.status !== 200) {
+ setServerError(
+ "Failed uploading resource icon file. Changes did not save!"
+ );
+ throw new Error(JSON.stringify(uploadResponse));
+ }
+ }
+
+ await router.push(`/resources/${resource.id}`);
},
onError: (error) => setServerError(error.message),
});
- const onSubmit: SubmitHandler = async (data) => {
- if (updateIconFile) {
- const data = new FormData();
- data.append("photo", updateIconFile);
-
- if (!resource?.id) {
- throw Error("Resource data missing for photo to upload");
- }
-
- const uploadResponse = await fetch(
- `/api/resources/photo/${resource.id}`,
- {
- method: "POST",
- body: data,
- }
- );
-
- if (uploadResponse.status !== 200) {
- setServerError(
- "Failed uploading resource icon file. Changes did not save!"
- );
- throw new Error(JSON.stringify(uploadResponse));
- }
- }
-
+ const onSubmit: SubmitHandler = (data) => {
mutate(data);
};