Skip to content

Commit

Permalink
Add check to modal if SN update will be a merge, #241
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielrindlaub committed Sep 5, 2024
1 parent cdc4148 commit 833d16b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const API_URLS = {
development: 'http://localhost:3000/dev/external', // if serving animl-api locally
// development: 'https://ko0yratczi.execute-api.us-west-2.amazonaws.com/dev/external', // if using dev animl-api stack on AWS
// development: 'http://localhost:3000/dev/external', // if serving animl-api locally
development: 'https://ko0yratczi.execute-api.us-west-2.amazonaws.com/dev/external', // if using dev animl-api stack on AWS
staging: 'https://ko0yratczi.execute-api.us-west-2.amazonaws.com/dev/external',
production: 'https://4634jgo56f.execute-api.us-west-2.amazonaws.com/prod/external/',
};
Expand Down
34 changes: 26 additions & 8 deletions src/features/cameras/UpdateCameraSerialNumberForm.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { Formik, Form, Field, ErrorMessage } from 'formik';
import * as Yup from 'yup';
import Button from '../../components/Button';
import {
FormWrapper,
// FormSubheader,
FieldRow,
FormFieldWrapper,
ButtonRow,
FormError,
} from '../../components/Form';
import { SimpleSpinner, SpinnerOverlay } from '../../components/Spinner';
import { selectSelectedCamera } from '../projects/projectsSlice';
import { selectSelectedProject, selectSelectedCamera } from '../projects/projectsSlice';
import {
updateCameraSerialNumber,
fetchTask,
Expand All @@ -31,11 +30,20 @@ const UpdateCameraSerialNumberForm = () => {
const dispatch = useDispatch();

const handleUpdateSerialNumberSubmit = (formVals) => {
console.log('handleUpdateSerialNumberSubmit() - formVals:', formVals);
console.log('selectedCamera: ', selectedCamera);
dispatch(updateCameraSerialNumber({ cameraId: selectedCamera, newId: formVals.serialNumber }));
};

const project = useSelector(selectSelectedProject);
const cameraIds = project?.cameraConfigs.map((cc) => cc._id);
const [isMerge, setIsMerge] = useState(false);
const handleInputChange = (values) => {
if (values.serialNumber === selectedCamera) {
setIsMerge(false);
return;
}
setIsMerge(cameraIds.includes(values.serialNumber));
};

// fetch task status
const updateCameraSerialNumberLoading = useSelector(selectCameraSerialNumberLoading);
useEffect(() => {
Expand All @@ -61,13 +69,23 @@ const UpdateCameraSerialNumberForm = () => {
validationSchema={updateSerialNumberSchema}
onSubmit={(values) => handleUpdateSerialNumberSubmit(values)}
>
{({ isValid, dirty }) => (
{({ isValid, dirty, values }) => (
<Form>
{/* <FormSubheader>Update Camera Serial Number</FormSubheader> */}
<p>Update Camera Serial Number</p>
{isMerge && (
<p>
NOTE: a camera with this serial number already exists. By updating the selected
camera, you will be merging images from the selected camera to the target camera
</p>
)}
<FieldRow>
<FormFieldWrapper>
{/* <label htmlFor="serialNumber">New Serial Number</label> */}
<Field name="serialNumber" id="serialNumber" />
<Field
name="serialNumber"
id="serialNumber"
onKeyUp={() => handleInputChange(values)}
/>
<ErrorMessage component={FormError} name="cameraId" />
</FormFieldWrapper>
</FieldRow>
Expand Down
2 changes: 0 additions & 2 deletions src/features/filters/CameraFilterSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ const CameraFilterSection = ({ camConfig, activeDeps }) => {
const [expanded, setExpanded] = useState(false);
const dispatch = useDispatch();

console.log('camConfig', camConfig);

// format default deployment names
const deployments = camConfig.deployments.map((dep) => {
const name = dep.name === 'default' ? `${camConfig._id} (default)` : dep.name;
Expand Down
1 change: 1 addition & 0 deletions src/features/tasks/tasksSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ export const fetchTask = (taskId) => {
dispatch(setModalOpen(false));
dispatch(setModalContent(null));
dispatch(fetchProjects({ _ids: [selectedProj._id] }));
// TODO: do we need to reset Project slice's selectedCamera as well?
},
FAIL: (res) => dispatch(updateCameraSerialNumberFailure(res)),
},
Expand Down

0 comments on commit 833d16b

Please sign in to comment.