diff --git a/src/people/components/EditCondition.tsx b/src/people/components/EditCondition.tsx index 40c02570..38a1b2ac 100644 --- a/src/people/components/EditCondition.tsx +++ b/src/people/components/EditCondition.tsx @@ -1,6 +1,6 @@ import { Button, FormControl, InputLabel, MenuItem, Select, SelectChangeEvent, TextField } from "@mui/material"; import React from "react"; -import { ApiHelper, SearchCondition, Permissions, GroupInterface } from "@churchapps/apphelper"; +import { ApiHelper, SearchCondition, Permissions, GroupInterface, Loading } from "@churchapps/apphelper"; interface Props { conditionAdded: (condition: any) => void @@ -11,6 +11,7 @@ export function EditCondition(props: Props) { const [condition, setCondition] = React.useState({ field: "displayName", operator: "equals", value: "" }); const [loadedOptions, setLoadedOptions] = React.useState([]); const [loadedOptionsField, setLoadedOptionsField] = React.useState(""); + const [loadingOptions, setLoadingOptions] = React.useState(false); const handleChange = (e: React.ChangeEvent | SelectChangeEvent) => { let c = { ...condition } @@ -18,6 +19,8 @@ export function EditCondition(props: Props) { case "field": c.field = e.target.value; + c.operator = "equals"; + c.value = ""; break; case "operator": c.operator = e.target.value; @@ -64,12 +67,12 @@ export function EditCondition(props: Props) { case "birthMonth": case "anniversaryMonth": options = [January, February, March, April, May, June, July, August, September, October, November, December] - setDefaultValue("January"); + setDefaultValue("1"); result = getValueSelect(options); break; case "birthDate": case "anniversary": - result = + result = break; case "age": case "yearsMarried": @@ -86,10 +89,12 @@ export function EditCondition(props: Props) { if (condition.field !== loadedOptionsField) { setLoadedOptionsField(condition.field); if (condition.field === "groupMember") { + setLoadingOptions(true); ApiHelper.get("/groups", "MembershipApi").then((groups: GroupInterface[]) => { const options: any[] = []; groups.forEach(g => { options.push({ value: g.id, text: g.name }); }); setLoadedOptions(options); + setLoadingOptions(false); }); } } @@ -103,17 +108,7 @@ export function EditCondition(props: Props) { ) const getOperatorOptions = () => { - let result = [ - =, - contains, - starts with, - ends with, - >, - >=, - <, - <=, - != - ] + let result = []; switch (condition?.field) { case "gender": @@ -133,6 +128,19 @@ export function EditCondition(props: Props) { is not member of ] break; + default: + result = [ + =, + contains, + starts with, + ends with, + >, + >=, + <, + <=, + != + ] + break; } return result; } @@ -175,7 +183,7 @@ export function EditCondition(props: Props) { - {getValueField()} + {loadingOptions ? : <>{getValueField()}} } diff --git a/src/people/components/PeopleSearch.tsx b/src/people/components/PeopleSearch.tsx index c925b409..94214c3d 100644 --- a/src/people/components/PeopleSearch.tsx +++ b/src/people/components/PeopleSearch.tsx @@ -94,7 +94,7 @@ export function PeopleSearch(props: Props) { return result; } - const getAdvancedSearch = () => (Simple} saveFunction={handleAdvancedSearch} saveText="Search" help="chums/advanced-search"> + const getAdvancedSearch = () => (Simple} saveFunction={handleAdvancedSearch} saveText="Search" isSubmitting={conditions.length < 1} help="chums/advanced-search">

All people where:

{getDisplayConditions()} {getAddCondition()}