-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87ee0c7
commit fd02748
Showing
16 changed files
with
490 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/music-catalogue-ui/components/manufacturers/deleteManufacturerActionIcon.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useCallback } from "react"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faTrashAlt } from "@fortawesome/free-solid-svg-icons"; | ||
import { | ||
apiDeleteManufacturer, | ||
apiFetchManufacturers, | ||
} from "@/helpers/api/apiManufacturers"; | ||
|
||
/** | ||
* Icon and associated action to delete a manufacturer | ||
* @param {*} manufacturer | ||
* @param {*} logout | ||
* @param {*} setManufacturers | ||
* @param {*} setError | ||
* @returns | ||
*/ | ||
const DeleteManufacturerActionIcon = ({ | ||
manufacturer, | ||
logout, | ||
setManufacturers, | ||
setError, | ||
}) => { | ||
/* Callback to prompt for confirmation and delete amanufacturer */ | ||
const confirmDeleteManufacturer = useCallback( | ||
async (e) => { | ||
// Prevent the default action associated with the click event | ||
e.preventDefault(); | ||
|
||
// Show a confirmation message and get the user response | ||
const message = `This will delete the manufacturer "${manufacturer.name}" - click OK to confirm`; | ||
const result = confirm(message); | ||
|
||
// If they've confirmed the deletion ... | ||
if (result) { | ||
// ... delete the manufacturer and confirm the API call was successful | ||
try { | ||
const result = await apiDeleteManufacturer(manufacturer.id, logout); | ||
if (result) { | ||
// Successful, so refresh the manufacturer list | ||
const fetchedManufacturers = await apiFetchManufacturers(logout); | ||
setManufacturers(fetchedManufacturers); | ||
} | ||
} catch (ex) { | ||
setError(`Error deleting the equipment type: ${ex.message}`); | ||
} | ||
} | ||
}, | ||
[manufacturer, logout, setManufacturers, setError] | ||
); | ||
|
||
return ( | ||
<FontAwesomeIcon | ||
icon={faTrashAlt} | ||
onClick={(e) => confirmDeleteManufacturer(e)} | ||
/> | ||
); | ||
}; | ||
|
||
export default DeleteManufacturerActionIcon; |
113 changes: 113 additions & 0 deletions
113
src/music-catalogue-ui/components/manufacturers/manufacturerEditor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import styles from "./manufacturerEditor.module.css"; | ||
import pages from "@/helpers/navigation"; | ||
import FormInputField from "../common/formInputField"; | ||
import { useState, useCallback } from "react"; | ||
import { | ||
apiCreateManufacturer, | ||
apiUpdateManufacturer, | ||
} from "@/helpers/api/apiManufacturers"; | ||
|
||
/** | ||
* Component to render the manufacturer editor | ||
* @param {*} manufacturer | ||
* @param {*} navigate | ||
* @param {*} logout | ||
*/ | ||
const EquipmentTypeEditor = ({ manufacturer, navigate, logout }) => { | ||
// Set up state | ||
const initialName = manufacturer != null ? manufacturer.name : null; | ||
const [name, setName] = useState(initialName); | ||
const [error, setError] = useState(""); | ||
|
||
const saveManufacturer = useCallback( | ||
async (e) => { | ||
// Prevent the default action associated with the click event | ||
e.preventDefault(); | ||
|
||
// Clear pre-existing errors | ||
setError(""); | ||
|
||
try { | ||
// Either add or update the manufacturer, depending on whether there's an | ||
// existing manufacturer or not | ||
let updatedEquipmentType = null; | ||
if (manufacturer == null) { | ||
// Create the manufacturer | ||
updatedEquipmentType = await apiCreateManufacturer(name, logout); | ||
} else { | ||
// Update the existing manufacturer | ||
updatedEquipmentType = await apiUpdateManufacturer( | ||
manufacturer.id, | ||
name, | ||
logout | ||
); | ||
} | ||
|
||
// Go back to the manufacturer list, which should reflect the updated details | ||
navigate({ | ||
page: pages.manufacturers, | ||
}); | ||
} catch (ex) { | ||
setError( | ||
`Error saving the updated manufacturer details: ${ex.message}` | ||
); | ||
} | ||
}, | ||
[manufacturer, logout, name, navigate] | ||
); | ||
|
||
// Set the page title | ||
const pageTitle = | ||
manufacturer != null ? manufacturer.name : "New Manufacturer"; | ||
|
||
return ( | ||
<> | ||
<div className="row mb-2 pageTitle"> | ||
<h5 className="themeFontColor text-center">{pageTitle}</h5> | ||
</div> | ||
<div className={styles.manufacturerEditorFormContainer}> | ||
<form className={styles.manufacturerEditorForm}> | ||
<div className="row"> | ||
{error != "" ? ( | ||
<div className={styles.manufacturerEditorError}>{error}</div> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
<div className="row align-items-start"> | ||
<FormInputField | ||
label="Name" | ||
name="name" | ||
value={name} | ||
setValue={setName} | ||
/> | ||
</div> | ||
<div className="d-grid gap-2 mt-3"></div> | ||
<div className="d-grid gap-2 mt-3"></div> | ||
<div className={styles.manufacturerEditorButton}> | ||
<button | ||
className="btn btn-primary" | ||
onClick={(e) => saveManufacturer(e)} | ||
> | ||
Save | ||
</button> | ||
</div> | ||
<div className={styles.manufacturerEditorButton}> | ||
<button | ||
className="btn btn-primary" | ||
onClick={() => | ||
navigate({ | ||
page: pages.manufacturers, | ||
}) | ||
} | ||
> | ||
Cancel | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default EquipmentTypeEditor; |
27 changes: 27 additions & 0 deletions
27
src/music-catalogue-ui/components/manufacturers/manufacturerEditor.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.manufacturerEditorFormContainer { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.manufacturerEditorForm { | ||
width: 80%; | ||
padding-top: 20px; | ||
padding-bottom: 20px; | ||
} | ||
|
||
.manufacturerEditorFormLabel { | ||
font-size: 14px; | ||
font-weight: 600; | ||
color: rgb(34, 34, 34); | ||
} | ||
|
||
.manufacturerEditorButton { | ||
margin-left: 10px; | ||
float: right; | ||
} | ||
|
||
.manufacturerEditorError { | ||
font-weight: bold; | ||
color: red; | ||
} |
66 changes: 66 additions & 0 deletions
66
src/music-catalogue-ui/components/manufacturers/manufacturerList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import styles from "./manufacturerList.module.css"; | ||
import pages from "@/helpers/navigation"; | ||
import useManufacturers from "@/hooks/useManufacturers"; | ||
import { useState } from "react"; | ||
import ManufacturerRow from "./manufacturerRow"; | ||
|
||
/** | ||
* Component to render a table listing all the manufacturers in the register | ||
* @param {*} navigate | ||
* @param {*} logout | ||
* @returns | ||
*/ | ||
const ManufacturerList = ({ navigate, logout }) => { | ||
const { manufacturers, setManufacturers } = useManufacturers(logout); | ||
const [error, setError] = useState(""); | ||
|
||
return ( | ||
<> | ||
<div className="row mb-2 pageTitle"> | ||
<h5 className="themeFontColor text-center">Manufacturers</h5> | ||
</div> | ||
<div className="row"> | ||
{error != "" ? ( | ||
<div className={styles.manufacturerListError}>{error}</div> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
<table className="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
</tr> | ||
</thead> | ||
{manufacturers != null && ( | ||
<tbody> | ||
{manufacturers.map((m) => ( | ||
<ManufacturerRow | ||
key={m.id} | ||
manufacturer={m} | ||
navigate={navigate} | ||
logout={logout} | ||
setManufacturers={setManufacturers} | ||
setError={setError} | ||
/> | ||
))} | ||
</tbody> | ||
)} | ||
</table> | ||
<div className={styles.manufacturerListAddButton}> | ||
<button | ||
className="btn btn-primary" | ||
onClick={() => | ||
navigate({ | ||
page: pages.manufacturerEditor, | ||
}) | ||
} | ||
> | ||
Add | ||
</button> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default ManufacturerList; |
9 changes: 9 additions & 0 deletions
9
src/music-catalogue-ui/components/manufacturers/manufacturerList.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.manufacturerListAddButton { | ||
float: right; | ||
} | ||
|
||
.manufacturerListError { | ||
font-weight: bold; | ||
color: red; | ||
text-align: center; | ||
} |
Oops, something went wrong.