2025-09-30 13:25:11 +01:00
|
|
|
import { Field, FieldArray, Form, Formik } from "formik";
|
|
|
|
|
import FormGroup from "../components/FormGroup";
|
|
|
|
|
import type { FormValues, Hotlist } from "../../../types/types";
|
2025-09-30 14:51:37 +01:00
|
|
|
import { useSoundContext } from "../../../context/SoundContext";
|
2025-09-30 15:32:00 +01:00
|
|
|
import { toast } from "sonner";
|
2025-09-30 13:25:11 +01:00
|
|
|
|
|
|
|
|
const SoundSettingsFields = () => {
|
2025-09-30 14:51:37 +01:00
|
|
|
const { state, dispatch } = useSoundContext();
|
2025-09-30 13:25:11 +01:00
|
|
|
const hotlists: Hotlist[] = [
|
|
|
|
|
{ name: "hotlist0", sound: "" },
|
|
|
|
|
{ name: "hotlist1", sound: "" },
|
|
|
|
|
{ name: "hotlist2", sound: "" },
|
|
|
|
|
];
|
|
|
|
|
|
2025-10-01 15:21:07 +01:00
|
|
|
const soundOptions = state?.soundOptions?.map((soundOption) => ({
|
|
|
|
|
value: soundOption?.name,
|
|
|
|
|
label: soundOption?.name,
|
|
|
|
|
}));
|
2025-09-30 13:25:11 +01:00
|
|
|
|
|
|
|
|
const initialValues: FormValues = {
|
2025-09-30 14:51:37 +01:00
|
|
|
sightingSound: state.sightingSound ?? "switch",
|
|
|
|
|
NPEDsound: state.NPEDsound ?? "popup",
|
2025-09-30 13:25:11 +01:00
|
|
|
hotlists,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSubmit = (values: FormValues) => {
|
2025-09-30 14:51:37 +01:00
|
|
|
dispatch({ type: "UPDATE", payload: values });
|
2025-09-30 15:32:00 +01:00
|
|
|
toast.success("Sound settings updated");
|
2025-09-30 13:25:11 +01:00
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<Formik initialValues={initialValues} onSubmit={handleSubmit}>
|
|
|
|
|
{({ values }) => (
|
|
|
|
|
<Form className="flex flex-col space-y-3">
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="sightingSound">Sighting Sound</label>
|
|
|
|
|
<Field
|
|
|
|
|
as="select"
|
|
|
|
|
name="sightingSound"
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
|
|
|
|
>
|
2025-10-01 15:21:07 +01:00
|
|
|
{soundOptions?.map(({ value, label }) => {
|
2025-09-30 13:25:11 +01:00
|
|
|
return (
|
|
|
|
|
<option key={value} value={value}>
|
|
|
|
|
{label}
|
|
|
|
|
</option>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Field>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<label htmlFor="NPEDsound">NPED notification Sound</label>
|
|
|
|
|
<Field
|
|
|
|
|
as="select"
|
|
|
|
|
name="NPEDsound"
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
|
|
|
|
>
|
2025-10-01 15:21:07 +01:00
|
|
|
{soundOptions?.map(({ value, label }) => (
|
2025-09-30 13:25:11 +01:00
|
|
|
<option key={value} value={value}>
|
|
|
|
|
{label}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</Field>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
<div>
|
|
|
|
|
<h3 className="text-lg font-semibold mb-2">Hotlist Sounds</h3>
|
|
|
|
|
<FormGroup>
|
|
|
|
|
<FieldArray
|
|
|
|
|
name="hotlists"
|
|
|
|
|
render={() => (
|
2025-09-30 15:32:00 +01:00
|
|
|
<div className="w-full m-2">
|
2025-09-30 13:25:11 +01:00
|
|
|
{values.hotlists.length > 0 ? (
|
|
|
|
|
values.hotlists.map((hotlist, index) => (
|
|
|
|
|
<div
|
|
|
|
|
key={hotlist.name}
|
2025-09-30 15:32:00 +01:00
|
|
|
className="flex items-center m-2 w-full justify-between"
|
2025-09-30 13:25:11 +01:00
|
|
|
>
|
|
|
|
|
<label
|
|
|
|
|
htmlFor={`hotlists.${index}.sound`}
|
|
|
|
|
className="w-32 shrink-0"
|
|
|
|
|
>
|
|
|
|
|
{hotlist.name}
|
|
|
|
|
</label>
|
|
|
|
|
<Field
|
|
|
|
|
as="select"
|
|
|
|
|
name={`hotlists.${index}.sound`}
|
|
|
|
|
id={`hotlists.${index}.sound`}
|
|
|
|
|
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
|
|
|
|
|
>
|
2025-10-01 15:21:07 +01:00
|
|
|
{soundOptions?.map(({ value, label }) => (
|
2025-09-30 13:25:11 +01:00
|
|
|
<option key={value} value={value}>
|
|
|
|
|
{label}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</Field>
|
|
|
|
|
</div>
|
|
|
|
|
))
|
|
|
|
|
) : (
|
2025-09-30 15:32:00 +01:00
|
|
|
<p>No hotlists yet, Add one</p>
|
2025-09-30 13:25:11 +01:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
type="submit"
|
|
|
|
|
className="w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5"
|
|
|
|
|
>
|
|
|
|
|
Save Settings
|
|
|
|
|
</button>
|
|
|
|
|
</Form>
|
|
|
|
|
)}
|
|
|
|
|
</Formik>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SoundSettingsFields;
|