add form to edit subscription
This commit is contained in:
@@ -8,23 +8,6 @@ from layercake.dynamodb import (
|
||||
from ...conftest import HttpApiProxy, LambdaContext
|
||||
|
||||
|
||||
def test_subscription(
|
||||
app,
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/e63a579a-4719-4d64-816f-f1650ca73753',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
|
||||
def test_add_subscription(
|
||||
app,
|
||||
seeds,
|
||||
@@ -38,7 +21,7 @@ def test_add_subscription(
|
||||
raw_path=f'/orgs/{org_id}/subscription',
|
||||
method=HTTPMethod.POST,
|
||||
body={
|
||||
'name': 'pytest subscribed',
|
||||
'name': 'pytest',
|
||||
'billing_day': 1,
|
||||
'payment_method': 'MANUAL',
|
||||
},
|
||||
@@ -55,4 +38,4 @@ def test_add_subscription(
|
||||
|
||||
assert r['metadata']['billing_day'] == 1
|
||||
assert r['metadata']['payment_method'] == 'MANUAL'
|
||||
assert r['subscription']['name'] == 'pytest subscribed'
|
||||
assert r['subscription']['name'] == 'pytest'
|
||||
|
||||
@@ -60,7 +60,7 @@ export async function action({ params, request, context }: Route.ActionArgs) {
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
const r = await req({
|
||||
await req({
|
||||
url: `orgs/${params.id}/subscription`,
|
||||
headers: new Headers({ 'Content-Type': 'application/json' }),
|
||||
method: method as HttpMethod,
|
||||
@@ -69,8 +69,6 @@ export async function action({ params, request, context }: Route.ActionArgs) {
|
||||
context
|
||||
})
|
||||
|
||||
console.log(r)
|
||||
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -81,11 +79,12 @@ export default function Route({}: Route.ComponentProps) {
|
||||
const form = useForm<Schema>({
|
||||
defaultValues: {
|
||||
plan: subscribed ? 'FLEXIVEL' : 'NOTHING',
|
||||
subscription_frozen: !!org?.subscription_frozen,
|
||||
...org?.subscription
|
||||
},
|
||||
resolver: zodResolver(formSchema)
|
||||
})
|
||||
const { handleSubmit, formState, watch } = form
|
||||
const { handleSubmit, formState, watch, reset } = form
|
||||
const plan = watch('plan')
|
||||
|
||||
const onSubmit = async ({ plan, ...data }: Schema) => {
|
||||
@@ -93,7 +92,13 @@ export default function Route({}: Route.ComponentProps) {
|
||||
fetcher.submit(null, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
return
|
||||
|
||||
return reset({
|
||||
plan: 'NOTHING',
|
||||
billing_day: 1,
|
||||
payment_method: undefined,
|
||||
subscription_frozen: false
|
||||
})
|
||||
}
|
||||
|
||||
fetcher.submit(JSON.stringify({ name: org.name, ...data }), {
|
||||
@@ -102,8 +107,6 @@ export default function Route({}: Route.ComponentProps) {
|
||||
})
|
||||
}
|
||||
|
||||
console.log(org)
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
@@ -159,6 +162,7 @@ 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>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { Org as Org_ } from '../_app.orgs._index/columns'
|
||||
|
||||
export type Subscription = {
|
||||
billing_day: number
|
||||
payment_method: 'BANK_SLIP' | 'MANUAL'
|
||||
}
|
||||
|
||||
export type Address = {
|
||||
address1: string
|
||||
address2: string
|
||||
}
|
||||
|
||||
export type Org = Org_ & {
|
||||
address?: Address
|
||||
subscription?: Subscription
|
||||
subscription_frozen?: boolean
|
||||
}
|
||||
@@ -55,8 +55,13 @@ export async function loader({ params, request, context }: Route.LoaderArgs) {
|
||||
|
||||
export function shouldRevalidate({
|
||||
currentParams,
|
||||
nextParams
|
||||
nextParams,
|
||||
actionResult
|
||||
}: ShouldRevalidateFunctionArgs) {
|
||||
if (actionResult?.ok) {
|
||||
return true
|
||||
}
|
||||
|
||||
return currentParams.id !== nextParams.id
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user