add feedback
This commit is contained in:
@@ -3,6 +3,7 @@ import type { Route } from './+types/route'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { useFetcher, useOutletContext } from 'react-router'
|
||||
import { toast } from 'sonner'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { Button } from '@repo/ui/components/ui/button'
|
||||
@@ -53,17 +54,17 @@ export async function action({ params, request, context }: Route.ActionArgs) {
|
||||
const method = request.method
|
||||
|
||||
if (method === 'DELETE') {
|
||||
await req({
|
||||
const r = await req({
|
||||
url: `orgs/${params.id}/subscription`,
|
||||
method: HttpMethod.DELETE,
|
||||
request,
|
||||
context
|
||||
})
|
||||
|
||||
return { ok: true }
|
||||
return { ok: r.ok }
|
||||
}
|
||||
|
||||
await req({
|
||||
const r = await req({
|
||||
url: `orgs/${params.id}/subscription`,
|
||||
headers: new Headers({ 'Content-Type': 'application/json' }),
|
||||
method: method as HttpMethod,
|
||||
@@ -72,7 +73,7 @@ export async function action({ params, request, context }: Route.ActionArgs) {
|
||||
context
|
||||
})
|
||||
|
||||
return { ok: true }
|
||||
return { ok: r.ok }
|
||||
}
|
||||
|
||||
export default function Route({}: Route.ComponentProps) {
|
||||
@@ -92,18 +93,20 @@ export default function Route({}: Route.ComponentProps) {
|
||||
|
||||
const onSubmit = async ({ plan, ...data }: Schema) => {
|
||||
if (plan === 'NOTHING') {
|
||||
fetcher.submit(null, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
fetcher.submit(null, { method: 'DELETE' })
|
||||
|
||||
toast.info('O plano foi removido')
|
||||
|
||||
return reset({
|
||||
plan: 'NOTHING',
|
||||
billing_day: 1,
|
||||
payment_method: undefined,
|
||||
billing_day: '',
|
||||
payment_method: '',
|
||||
subscription_frozen: false
|
||||
})
|
||||
} as any)
|
||||
}
|
||||
|
||||
toast.success('O plano foi atualizado')
|
||||
|
||||
fetcher.submit(JSON.stringify({ name: org.name, ...data }), {
|
||||
method: subscribed ? 'PUT' : 'POST',
|
||||
encType: 'application/json'
|
||||
@@ -165,7 +168,6 @@ export default function Route({}: Route.ComponentProps) {
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="billing_day"
|
||||
defaultValue={1}
|
||||
render={({ field: { onChange, ...field } }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Dia para faturar</FormLabel>
|
||||
|
||||
Reference in New Issue
Block a user