diff --git a/api/database.json b/api/database.json
index 13e33ac..e2ad6ae 100644
--- a/api/database.json
+++ b/api/database.json
@@ -1,35 +1,37 @@
+{
+ "serviceRequests": [
{
- "serviceRequests" : [
- {
- "id": 1,
- "description": "Aut sint voluptatem fugit eius quas molestiae modi.",
- "address": "34445 Bianka Ports",
- "budget": 400,
- "neededBy": "2021-08-27"
- }
- ],
-
- "employeeTable" : [
- {
- "id": 1,
- "empName": "Merle Baumgardner"
- },
- {
- "id": 2,
- "empName": "Maude Baumgardner"
- }
-
- ],
- "jobTable" : [
- {
- "id": null,
- "serviceRequestId": 1,
- "employeeId": 1,
- "jobStatusComplete": false
- },
- {
-
- }
-
- ]
-}
+ "id": 1,
+ "description": "Aut sint voluptatem fugit eius quas molestiae modi.",
+ "address": "34445 Bianka Ports",
+ "budget": 400,
+ "neededBy": "2021-08-27"
+ },
+ {
+ "description": "Install holding tank and pump system for a rural groundwater spring water system",
+ "address": "49320 NW Ruby Lane, Forest Grove, OR, 97116",
+ "budget": "5000",
+ "neededBy": "2021-12-05",
+ "id": 2
+ }
+ ],
+ "employeeTable": [
+ {
+ "id": 1,
+ "empName": "Merle Baumgardner"
+ },
+ {
+ "id": 2,
+ "empName": "Maude Baumgardner"
+ }
+ ],
+ "jobTable": [
+ {
+ "id": null,
+ "serviceRequestId": 1,
+ "employeeId": 1,
+ "jobStatusComplete": false
+ },
+ {}
+ ]
+}
\ No newline at end of file
diff --git a/scripts/Requests.js b/scripts/Requests.js
index d5513b6..029714f 100644
--- a/scripts/Requests.js
+++ b/scripts/Requests.js
@@ -1,13 +1,16 @@
import { getRequests } from "./dataAccess.js"
+// requests exports the requests stored in application state as requests passed in as an ordered list wrapped inside an unordered list
export const Requests = () => {
const requests = getRequests()
-
+ const convertRequestToListElement = (requests) => {
+ return `
${requests.description}`
+ }
let html = `
${
- requests.map().join("")
- }
+ requests.map(convertRequestToListElement).join("")
+ }
`
diff --git a/scripts/ServiceForm.js b/scripts/ServiceForm.js
new file mode 100644
index 0000000..2cd032f
--- /dev/null
+++ b/scripts/ServiceForm.js
@@ -0,0 +1,49 @@
+import { sendRequest } from "./dataAccess.js";
+
+export const ServiceForm = () => {
+ let html = `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `
+
+ return html
+}
+
+const mainContainer = document.querySelector("#container")
+
+mainContainer.addEventListener("click", clickEvent => {
+ if (clickEvent.target.id === "submitRequest") {
+ // Get what the user typed into the form fields
+ const userDescription = document.querySelector("input[name='serviceDescription']").value
+ const userAddress = document.querySelector("input[name='serviceAddress']").value
+ const userBudget = document.querySelector("input[name='serviceBudget']").value
+ const userDate = document.querySelector("input[name='serviceDate']").value
+
+ // Make an object out of the user input
+ const dataToSendToAPI = {
+ description: userDescription,
+ address: userAddress,
+ budget: userBudget,
+ neededBy: userDate
+ }
+
+ // Send the data to the API for permanent storage
+ sendRequest(dataToSendToAPI)
+ }
+})
diff --git a/scripts/SinkRepair.js b/scripts/SinkRepair.js
index 1fb8e54..84cb215 100644
--- a/scripts/SinkRepair.js
+++ b/scripts/SinkRepair.js
@@ -1,10 +1,11 @@
+import { ServiceForm } from "./ServiceForm.js"
import { Requests } from "./Requests.js"
-
export const SinkRepair = () => {
return `
Maude and Merle's Sink Repair
diff --git a/scripts/dataAccess.js b/scripts/dataAccess.js
index 0a2da15..a393b13 100644
--- a/scripts/dataAccess.js
+++ b/scripts/dataAccess.js
@@ -38,6 +38,38 @@ export const fetchEmpTable = () => {
}
)
}
+export const sendRequest = (userServiceRequest) => {
+ const fetchOptions = {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json"
+ },
+ body: JSON.stringify(userServiceRequest)
+ }
+
+
+ return fetch(`${API}/serviceRequests`, fetchOptions)
+ .then(response => response.json())
+ .then(() => {
+
+ })
+}
+
+return fetch(`${API}/requests`, fetchOptions)
+.then(response => response.json())
+.then(() => {
+ mainContainer.dispatchEvent(new CustomEvent("stateChanged"))
+})
+
+mainContainer.addEventListener(
+ "stateChanged",
+ customEvent => {
+ render()
+ }
+)
+
+
+
export const getRequests = () => {
return applicationState.serviceRequests.map(serviceRequest => ({...serviceRequest}))
}
@@ -50,4 +82,4 @@ export const getJobTable = () => {
return applicationState.jobTable.map(job => ({...job}))
}
-// Need copies of permanent state set as empty arrays, matching the keys in your JSON file
\ No newline at end of file
+// Need copies of permanent state set as empty arrays, matching the keys in your JSON file
diff --git a/styles/button.css b/styles/button.css
new file mode 100644
index 0000000..0c5a889
--- /dev/null
+++ b/styles/button.css
@@ -0,0 +1,4 @@
+.button {
+ background-color:#6CD9FA;
+ color: #000000;
+}
diff --git a/styles/flex.css b/styles/flex.css
new file mode 100644
index 0000000..4ce3d92
--- /dev/null
+++ b/styles/flex.css
@@ -0,0 +1,4 @@
+.field {
+ display: flex;
+ flex-direction: column;
+}
\ No newline at end of file
diff --git a/styles/main.css b/styles/main.css
index e69de29..6c22527 100644
--- a/styles/main.css
+++ b/styles/main.css
@@ -0,0 +1,3 @@
+@import "flex.css";
+
+@import "button.css";