Car table update (#27)

This commit is contained in:
John Wu
2021-04-05 10:09:40 -07:00
committed by GitHub
parent 17f81822c0
commit 113cc97fea
5 changed files with 7 additions and 15 deletions

View File

@@ -49,18 +49,12 @@ const MainForm = () => {
const handleVehiclesChange = (event) => {
setSelectedVehicles(event.target.value);
};
const getCarIDs = () => {
if (!selectedVehicles) return [];
return selectedVehicles.map((vin) => {
return vehicles.find((vehicle) => vehicle.vin === vin).id;
});
};
const onSubmit = async (event) => {
try {
event.preventDefault();
const data = {
package_id: parseInt(packageid),
car_ids: getCarIDs(),
vins: selectedVehicles,
};
await createCarUpdates(data, token);
setMessage(

View File

@@ -96,7 +96,7 @@ const MainForm = () => {
{carUpdates.map((row) => (
<TableRow key={row.id}>
<TableCell align="center">{row.id}</TableCell>
<TableCell align="center">{`${row.car.vin} ${row.car.model} ${row.car.year}`}</TableCell>
<TableCell align="center">{row.vin}</TableCell>
<TableCell align="center">{row.status}</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}

View File

@@ -65,7 +65,6 @@ const MainForm = () => {
<Table>
<TableHead>
<TableRow>
<TableCell align="center">ID</TableCell>
<TableCell align="center">VIN</TableCell>
<TableCell align="center">Model</TableCell>
<TableCell align="center">Year</TableCell>
@@ -75,8 +74,7 @@ const MainForm = () => {
</TableHead>
<TableBody>
{vehicles.map((row) => (
<TableRow key={row.id}>
<TableCell align="center">{row.id}</TableCell>
<TableRow key={row.vin}>
<TableCell align="center">{row.vin}</TableCell>
<TableCell align="center">{row.model}</TableCell>
<TableCell align="center">{row.year}</TableCell>

View File

@@ -222,7 +222,7 @@ describe("UpdatesContext", () => {
data-testid="with-bad-data"
onClick={async () => {
result = await exec(
{ package_id: 1, car_ids: [] },
{ package_id: 1, vins: [] },
TEST_AUTH_OBJECT
);
}}
@@ -233,7 +233,7 @@ describe("UpdatesContext", () => {
result = await exec(
{
package_id: 1,
car_ids: [1, 2, 3],
vins: ["FISKER123", "FISKER124", "FISKER125"],
},
TEST_AUTH_OBJECT
);
@@ -284,7 +284,7 @@ describe("UpdatesContext", () => {
checkState("false", "", {
id: 1,
package_id: 1,
car_ids: [1, 2, 3],
vins: ["FISKER123", "FISKER124", "FISKER125"],
});
});
});

View File

@@ -125,7 +125,7 @@ const validateCreateCarUpdates = (data) => {
throw new Error("Package id required");
}
if (!data.car_ids || data.car_ids.length === 0) {
if (!data.vins || data.vins.length === 0) {
throw new Error("Car ids required");
}
};