Files
supabase/apps/studio/components/interfaces/Database/CronJobs/HttpRequestSection.tsx
T
Ivan VasilovandJoshen Lim fd3309c886 feat: UI for pg-cron (#29291)
* Add crons option in the database menu.

* Add react-hook-form to the studio package.json.

* Refactor the functionSelector to be used by other features.

* Add the bulk of the functionality for the cron UI. Some of the code is copy-pasted from functions feature, needs to be cleaned before merging.

* Tons of changes, the Create Cron sheet works now.

* Added some more functionality for the cronjob feature.

* Convert the Cron table to a listing with cards.

* Add click-to-copy in the Auth Hooks feature.

* Remove extra prop.

* Fix type errors.

* Fix some random issues. Fix the tests.

* Fix the tests.

* Add a style for disabled radio button item.

* Make the default SQL snippet. Handle the case pg_net is not installed.

* Fix the heading and save button when creating a new cron job.

* Change the name of the custom label in the schedule dropdown.

* Minor fixes.

* Rename all mentions of cronjobs to cron jobs.

* Always show the cron jobs link.

* Rename the link from crons to cron-jobs.

* Fix the disabled state for the stacked radio group.

* More minor fixes.

* More small fixes.

* Fix the tests.

* Minor UI tweaks

* More minor tweaks

* Add padding bottom

* Add feature flag for the cron ui.

* Fix the SQL function option.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-10-03 15:11:17 -02:30

76 lines
2.3 KiB
TypeScript

import { UseFormReturn } from 'react-hook-form'
import {
FormControl_Shadcn_,
FormField_Shadcn_,
FormItem_Shadcn_,
FormLabel_Shadcn_,
FormMessage_Shadcn_,
Input,
Select_Shadcn_,
SelectContent_Shadcn_,
SelectItem_Shadcn_,
SelectTrigger_Shadcn_,
SelectValue_Shadcn_,
SheetSection,
} from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { CreateCronJobForm } from './CreateCronJobSheet'
interface HttpRequestSectionProps {
form: UseFormReturn<CreateCronJobForm>
}
export const HttpRequestSection = ({ form }: HttpRequestSectionProps) => {
return (
<SheetSection className="flex flex-col gap-3">
<FormField_Shadcn_
control={form.control}
name="values.method"
render={({ field }) => (
<FormItem_Shadcn_>
<FormLabel_Shadcn_>Method</FormLabel_Shadcn_>
<Select_Shadcn_ onValueChange={field.onChange} value={field.value}>
<FormControl_Shadcn_>
<SelectTrigger_Shadcn_>
<SelectValue_Shadcn_ placeholder="Select a method for the HTTP request" />
</SelectTrigger_Shadcn_>
</FormControl_Shadcn_>
<SelectContent_Shadcn_>
<SelectItem_Shadcn_ value="GET">GET</SelectItem_Shadcn_>
<SelectItem_Shadcn_ value="POST">POST</SelectItem_Shadcn_>
</SelectContent_Shadcn_>
</Select_Shadcn_>
<FormMessage_Shadcn_ />
</FormItem_Shadcn_>
)}
/>
<FormField_Shadcn_
control={form.control}
name="values.endpoint"
render={({ field: { ref, ...rest } }) => (
<FormItemLayout label="Endpoint URL" className="gap-1">
<Input {...rest} placeholder="https://api.example.com/endpoint" />
</FormItemLayout>
)}
/>
<FormField_Shadcn_
control={form.control}
name="values.timeoutMs"
render={({ field: { ref, ...rest } }) => (
<FormItemLayout label="Timeout" className="gap-1">
<Input
{...rest}
type="number"
placeholder="1000"
actions={<p className="text-foreground-light pr-2">ms</p>}
/>
</FormItemLayout>
)}
/>
</SheetSection>
)
}