From 802f1cbd9dd07533963e0f8a8791110303dc4e02 Mon Sep 17 00:00:00 2001 From: Yangshun Date: Wed, 30 Jul 2025 11:45:57 +0800 Subject: [PATCH] [admin] misc: extract form into separate component --- apps/admin/src/components/ConversionsPage.tsx | 145 +++++++++++------- 1 file changed, 91 insertions(+), 54 deletions(-) diff --git a/apps/admin/src/components/ConversionsPage.tsx b/apps/admin/src/components/ConversionsPage.tsx index 8d70724ae..cc1c781d2 100644 --- a/apps/admin/src/components/ConversionsPage.tsx +++ b/apps/admin/src/components/ConversionsPage.tsx @@ -1,5 +1,6 @@ 'use client'; +import clsx from 'clsx'; import { useState } from 'react'; import useSWR from 'swr'; @@ -47,60 +48,15 @@ export default function ConversionsPage() { return (

Critical data

-
{ - e.preventDefault(); - - const formData = new FormData(e.currentTarget); - - setCountry(formData.get('country') as string); - setCountryFilter(formData.get('countryFilter') as CountryFilter); - }}> - -
- - - -
- -
+ { + setCountryFilter(countryFilterParam); + setCountry(countryParam); + }} + /> {isLoading &&
Loading...
} {error && (
Error: {error.toString()}
@@ -115,3 +71,84 @@ export default function ConversionsPage() {
); } + +function FilterForm({ + onSubmit, +}: { + onSubmit: ({ + country, + countryFilter, + }: Readonly<{ country: string; countryFilter: CountryFilter }>) => void; +}) { + const [countryFilter, setCountryFilter] = useState('none'); + + return ( +
{ + e.preventDefault(); + + const formData = new FormData(e.currentTarget); + + onSubmit({ + country: formData.get('country') as string, + countryFilter: formData.get('countryFilter') as CountryFilter, + }); + }}> +
+ + Country + +
+ {( + [ + { + label: 'None', + value: 'none', + }, + { + label: 'Include only', + value: 'include', + }, + { + label: 'Exclude', + value: 'exclude', + }, + ] as const + ).map((option) => ( + + ))} +
+
+ {countryFilter !== 'none' && ( + + )} + +
+ ); +}