diff --git a/public/locales/de/translation.json b/public/locales/de/translation.json
index e3590dd..e11748d 100644
--- a/public/locales/de/translation.json
+++ b/public/locales/de/translation.json
@@ -11,7 +11,8 @@
"close": "Schließen",
"save": "Speichern",
"delete": "Löschen",
- "confirm": "Bestätigen"
+ "confirm": "Bestätigen",
+ "create": "Erstellen"
},
"contactAdmin": "Bitte kontaktieren Sie einen Administrator"
},
diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json
index c839372..305803a 100644
--- a/public/locales/en/translation.json
+++ b/public/locales/en/translation.json
@@ -11,7 +11,8 @@
"close": "Close",
"save": "Save",
"delete": "Delete",
- "confirm": "Confirm"
+ "confirm": "Confirm",
+ "create": "Create"
},
"contactAdmin": "Please contact an administrator"
},
diff --git a/src/Components/AppRoutes/index.js b/src/Components/AppRoutes/index.js
index 8d5b924..f6bf0d0 100644
--- a/src/Components/AppRoutes/index.js
+++ b/src/Components/AppRoutes/index.js
@@ -54,7 +54,7 @@ export default function AppRoutes() {
}
/>
diff --git a/src/Components/MyModal/index.js b/src/Components/MyModal/index.js
index e24504f..9d80c1d 100644
--- a/src/Components/MyModal/index.js
+++ b/src/Components/MyModal/index.js
@@ -103,3 +103,29 @@ export function MyModalOnlyCloseButtonFooter({ onCancel }) {
return ;
}
+
+export function MyModalCloseSaveButtonFooter({ onCancel, onSave }) {
+ const { t } = useTranslation();
+
+ return (
+ <>
+
+
+ >
+ );
+}
+
+export function MyModalCloseCreateButtonFooter({ onCancel, onCreate }) {
+ const { t } = useTranslation();
+
+ return (
+ <>
+
+
+ >
+ );
+}
diff --git a/src/Pages/EquipmentDocumentation/CreateEquipmentDocumentationModal.js b/src/Pages/EquipmentDocumentation/CreateEquipmentDocumentationModal.js
index f994dce..8bf95a9 100644
--- a/src/Pages/EquipmentDocumentation/CreateEquipmentDocumentationModal.js
+++ b/src/Pages/EquipmentDocumentation/CreateEquipmentDocumentationModal.js
@@ -1,95 +1,241 @@
import { useNavigate, useParams } from "react-router-dom";
-import MyModal from "../../Components/MyModal";
-import { AppStyle, Constants } from "../../utils";
-import {
- Button,
- Card,
- Col,
- Divider,
- Modal,
- Row,
- Typography,
- Upload,
- message,
-} from "antd";
-import { useRef, useState } from "react";
+import MyModal, {
+ MyModalCloseCreateButtonFooter,
+ MyModalCloseSaveButtonFooter,
+} from "../../Components/MyModal";
+import { AppStyle, Constants, myFetch, myFetchContentType } from "../../utils";
+import { Button, Card, Col, Row, Select, Typography } from "antd";
+import { createRef, useRef, useState } from "react";
import TextArea from "antd/es/input/TextArea";
import Webcam from "react-webcam";
-import { CameraOutlined, PlusOutlined } from "@ant-design/icons";
+import {
+ CameraOutlined,
+ DeleteOutlined,
+ FullscreenOutlined,
+ PlusOutlined,
+} from "@ant-design/icons";
+import { DocumentationImage } from ".";
-const CameraComponent = () => {
- const [visible, setVisible] = useState(false);
- const [imageData, setImageData] = useState(null);
- const webcamRef = useRef();
+function UploadComponent({ index, setImagePreview }) {
+ const handleFileChange = (event) => {
+ const file = event.target.files[0];
+ console.log("file", event.target.files);
+ if (file) {
+ const reader = new FileReader();
+ reader.onload = () => {
+ //setImagePreview(URL.createObjectURL(file));
+ setImagePreview(reader.result);
- const handleCapture = () => {
- const imageSrc = webcamRef.current.getScreenshot();
- setImageData(imageSrc);
- };
-
- const handleClear = () => {
- setImageData(null);
- };
-
- const handleSave = () => {
- // Hier könntest du die Logik zum Speichern des Bildes implementieren.
- message.success("Bild gespeichert!");
- setVisible(false);
+ // base 64 string
+ // console.log(reader.result);
+ };
+ reader.readAsDataURL(file);
+ }
};
return (
-
+
+
+
+ );
+}
+
+function CameraComponent({ setImagePreview }) {
+ const [modalVisible, setModalVisible] = useState(false);
+ const [cameraVisible, setCameraVisible] = useState(false);
+ const webcamRef = useRef(null);
+
+ const handleCapture = () => {
+ const imageSrc = webcamRef.current.getScreenshot();
+ setImagePreview(imageSrc);
+
+ handleCancel();
+ };
+
+ const handleCancel = () => {
+ setCameraVisible(false);
+ // this is needed to close the camera correctly
+ setTimeout(() => setModalVisible(false), 100);
+ };
+
+ return (
+ <>
+ {
+ setModalVisible(true);
+ setCameraVisible(true);
+ }}
+ >
+
+
+
setVisible(false)}
+ isOpen={modalVisible}
+ onCancel={handleCancel}
footer={[
- ,
- ,
-
-
+ >
);
-};
+}
+
+export function NoteComponent({
+ viewMode,
+ index,
+ image,
+ onImageChange,
+ description,
+ onDescriptionChange,
+ onDeleteImage,
+}) {
+ return (
+
+
+ ]
+ : [
+ ,
+ ,
+ ,
+ ,
+ ]
+ }
+ >
+
+
+
+
+
+ {viewMode ? (
+ {description}
+ ) : (
+
+ )}
+
+
+ );
+}
+
+const emptyNote = { image: null, description: "" };
+
+const selectDocumentationTypeOptions = [
+ { value: 0, label: "Repair protocol" },
+ { value: 1, label: "Documentation" },
+];
export default function CreateEquipmentDocumentationModal({ isOpen }) {
const navigate = useNavigate();
- let { paramEquipmentId } = useParams();
+ let { paramStockItemId } = useParams();
- const [title, setTitle] = useState("");
+ const [title, setTitle] = useState("New documentation");
+ const [selectedDocumentationType, setSelectedDocumentationType] = useState(
+ selectDocumentationTypeOptions[0].value
+ );
+ const [notes, setNotes] = useState([emptyNote]);
const handleCancel = () =>
navigate(Constants.ROUTE_PATHS.EQUIPMENT_DOCUMENTATION);
- console.log("paramEquipmentId", paramEquipmentId);
+ const handleCreate = () => {
+ let obj = {
+ stockItemId: paramStockItemId,
+ type: selectedDocumentationType,
+ title: title,
+ notes: notes,
+ };
+
+ myFetch(`/equipment/documentation/create`, "POST", obj, {}).then((data) => {
+ console.log("data", data);
+ });
+ };
+
+ const handleDescriptionChange = (index) => (e) => {
+ const updatedNotes = [...notes];
+
+ updatedNotes[index] = {
+ ...updatedNotes[index],
+ description: e.target.value,
+ };
+
+ setNotes(updatedNotes);
+ };
+
+ const handleImageChange = (index) => (newImage) => {
+ const updatedNotes = [...notes];
+
+ updatedNotes[index] = {
+ ...updatedNotes[index],
+ image: newImage,
+ };
+
+ setNotes(updatedNotes);
+ };
+
+ const handleAddNote = () => setNotes([...notes, emptyNote]);
+
+ const isAddNoteButtonDisabled = () => {
+ const lastNote = notes[notes.length - 1];
+
+ return lastNote.image === null && lastNote.description === "";
+ };
return (
-
+
+ }
+ >
-
-
-
- console.log("upload")}
- >
-
-
- Upload
-
-
+
+ Documentation type
+
-
-
- Take
-
-
-
+
+ {notes.map((note, index) => (
+ handleImageChange(index)(null)}
+ />
+ ))}
-
+
+ }
+ onClick={handleAddNote}
+ >
+ Add note
+
+
);
}
diff --git a/src/Pages/EquipmentDocumentation/index.js b/src/Pages/EquipmentDocumentation/index.js
index 2798c70..ea35530 100644
--- a/src/Pages/EquipmentDocumentation/index.js
+++ b/src/Pages/EquipmentDocumentation/index.js
@@ -4,7 +4,9 @@ import { AppStyle, Constants, myFetch } from "../../utils";
import { useEffect, useState } from "react";
import { QrScanner } from "@yudiel/react-qr-scanner";
import EquipmentViewModal from "./EquipmentViewModal";
-import CreateEquipmentDocumentationModal from "./CreateEquipmentDocumentationModal";
+import CreateEquipmentDocumentationModal, {
+ NoteComponent,
+} from "./CreateEquipmentDocumentationModal";
import { Link } from "react-router-dom";
export default function EquipmentDocumentation({ isEquipmentCreateModalOpen }) {
@@ -107,6 +109,36 @@ export default function EquipmentDocumentation({ isEquipmentCreateModalOpen }) {
}));
}; */
+ const CreateDocumentationButton = () => {
+ return (
+
+ Create documentation
+
+ );
+ };
+
+ const DocumentationContent = ({ documentation }) => {
+ console.log("doc", documentation);
+
+ return (
+
+ {documentation.Title}
+
+ {documentation.Notes !== "" &&
+ JSON.parse(documentation.Notes).map((note, index) => (
+
+ ))}
+
+ );
+ };
+
return (
<>
@@ -147,7 +179,7 @@ export default function EquipmentDocumentation({ isEquipmentCreateModalOpen }) {
ScannerResult: {scannerResult}
- {scannerResult !== "" && equipmentDocumentation.length === 0 && (
+ {scannerResult !== "" && equipmentDocumentation.length === 0 ? (
-
- Create documentation
-
+
>
}
/>
+ ) : (
+ <>
+
+
+ {equipmentDocumentation.map((documentation, index) => (
+
+ ))}
+ >
)}
@@ -173,6 +209,30 @@ export default function EquipmentDocumentation({ isEquipmentCreateModalOpen }) {
);
}
+export function DocumentationImage({ image, imgStyle }) {
+ return image ? (
+
+ ) : (
+
+ No image selected
+
+ );
+}
+
/*
{
+ if (contentType === myFetchContentType.JSON) return "application/json";
+
+ return "multipart/form-data";
+ };
+
+ const getBody = () => {
+ if (!body) return null;
+
+ if (contentType === myFetchContentType.JSON) return JSON.stringify(body);
+
+ return body;
+ };
+
const requestOptions = {
method: method,
- headers: { ...myFetchDefaultHeaders, ...headers },
- body: body ? JSON.stringify(body) : null,
+ headers: {
+ "X-Authorization": getUserSessionFromLocalStorage(),
+ "Content-Type": getContentType(),
+ ...headers,
+ },
+ body: getBody(),
};
return fetch(`${Constants.API_ADDRESS}${url}`, requestOptions)