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