SearchForm.jsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. "use client";
  2. import React from "react";
  3. import { SEARCH_SCOPE } from "@/lib/frontend/search/urlState";
  4. import SearchQueryBox from "@/components/search/form/SearchQueryBox";
  5. import SearchScopeSelect from "@/components/search/form/SearchScopeSelect";
  6. import SearchLimitSelect from "@/components/search/form/SearchLimitSelect";
  7. import SearchSingleBranchCombobox from "@/components/search/form/SearchSingleBranchCombobox";
  8. import SearchMultiBranchPicker from "@/components/search/form/SearchMultiBranchPicker";
  9. export default function SearchForm({
  10. branch,
  11. qDraft,
  12. onQDraftChange,
  13. onSubmit,
  14. currentQuery,
  15. isSubmitting,
  16. isAdminDev,
  17. scope,
  18. onScopeChange,
  19. onSingleBranchChange,
  20. availableBranches,
  21. branchesStatus,
  22. selectedBranches,
  23. onToggleBranch,
  24. limit,
  25. onLimitChange,
  26. }) {
  27. const canSearch = typeof qDraft === "string" && qDraft.trim().length > 0;
  28. return (
  29. <div className="space-y-4">
  30. <form
  31. onSubmit={(e) => {
  32. e.preventDefault();
  33. if (!canSearch) return;
  34. onSubmit();
  35. }}
  36. className="space-y-3"
  37. >
  38. <SearchQueryBox
  39. qDraft={qDraft}
  40. onQDraftChange={onQDraftChange}
  41. onSubmit={onSubmit}
  42. currentQuery={currentQuery}
  43. isSubmitting={isSubmitting}
  44. canSearch={canSearch}
  45. />
  46. <div className="flex flex-wrap items-center gap-2">
  47. {isAdminDev ? (
  48. <SearchScopeSelect
  49. branch={branch}
  50. scope={scope}
  51. onScopeChange={onScopeChange}
  52. isSubmitting={isSubmitting}
  53. />
  54. ) : null}
  55. {isAdminDev && scope === SEARCH_SCOPE.SINGLE ? (
  56. <SearchSingleBranchCombobox
  57. branch={branch}
  58. branchesStatus={branchesStatus}
  59. availableBranches={availableBranches}
  60. onSingleBranchChange={onSingleBranchChange}
  61. isSubmitting={isSubmitting}
  62. />
  63. ) : null}
  64. <SearchLimitSelect
  65. limit={limit}
  66. onLimitChange={onLimitChange}
  67. isSubmitting={isSubmitting}
  68. />
  69. </div>
  70. </form>
  71. {isAdminDev && scope === SEARCH_SCOPE.MULTI ? (
  72. <SearchMultiBranchPicker
  73. branchesStatus={branchesStatus}
  74. availableBranches={availableBranches}
  75. selectedBranches={selectedBranches}
  76. onToggleBranch={onToggleBranch}
  77. isSubmitting={isSubmitting}
  78. />
  79. ) : null}
  80. </div>
  81. );
  82. }