add form to edit subscription
This commit is contained in:
@@ -8,23 +8,6 @@ from layercake.dynamodb import (
|
|||||||
from ...conftest import HttpApiProxy, LambdaContext
|
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(
|
def test_add_subscription(
|
||||||
app,
|
app,
|
||||||
seeds,
|
seeds,
|
||||||
@@ -38,7 +21,7 @@ def test_add_subscription(
|
|||||||
raw_path=f'/orgs/{org_id}/subscription',
|
raw_path=f'/orgs/{org_id}/subscription',
|
||||||
method=HTTPMethod.POST,
|
method=HTTPMethod.POST,
|
||||||
body={
|
body={
|
||||||
'name': 'pytest subscribed',
|
'name': 'pytest',
|
||||||
'billing_day': 1,
|
'billing_day': 1,
|
||||||
'payment_method': 'MANUAL',
|
'payment_method': 'MANUAL',
|
||||||
},
|
},
|
||||||
@@ -55,4 +38,4 @@ def test_add_subscription(
|
|||||||
|
|
||||||
assert r['metadata']['billing_day'] == 1
|
assert r['metadata']['billing_day'] == 1
|
||||||
assert r['metadata']['payment_method'] == 'MANUAL'
|
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 }
|
return { ok: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
const r = await req({
|
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,
|
||||||
@@ -69,8 +69,6 @@ export async function action({ params, request, context }: Route.ActionArgs) {
|
|||||||
context
|
context
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(r)
|
|
||||||
|
|
||||||
return { ok: true }
|
return { ok: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,11 +79,12 @@ export default function Route({}: Route.ComponentProps) {
|
|||||||
const form = useForm<Schema>({
|
const form = useForm<Schema>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
plan: subscribed ? 'FLEXIVEL' : 'NOTHING',
|
plan: subscribed ? 'FLEXIVEL' : 'NOTHING',
|
||||||
|
subscription_frozen: !!org?.subscription_frozen,
|
||||||
...org?.subscription
|
...org?.subscription
|
||||||
},
|
},
|
||||||
resolver: zodResolver(formSchema)
|
resolver: zodResolver(formSchema)
|
||||||
})
|
})
|
||||||
const { handleSubmit, formState, watch } = form
|
const { handleSubmit, formState, watch, reset } = form
|
||||||
const plan = watch('plan')
|
const plan = watch('plan')
|
||||||
|
|
||||||
const onSubmit = async ({ plan, ...data }: Schema) => {
|
const onSubmit = async ({ plan, ...data }: Schema) => {
|
||||||
@@ -93,7 +92,13 @@ export default function Route({}: Route.ComponentProps) {
|
|||||||
fetcher.submit(null, {
|
fetcher.submit(null, {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
})
|
})
|
||||||
return
|
|
||||||
|
return reset({
|
||||||
|
plan: 'NOTHING',
|
||||||
|
billing_day: 1,
|
||||||
|
payment_method: undefined,
|
||||||
|
subscription_frozen: false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fetcher.submit(JSON.stringify({ name: org.name, ...data }), {
|
fetcher.submit(JSON.stringify({ name: org.name, ...data }), {
|
||||||
@@ -102,8 +107,6 @@ export default function Route({}: Route.ComponentProps) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(org)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
@@ -159,6 +162,7 @@ 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>
|
||||||
|
|||||||
@@ -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({
|
export function shouldRevalidate({
|
||||||
currentParams,
|
currentParams,
|
||||||
nextParams
|
nextParams,
|
||||||
|
actionResult
|
||||||
}: ShouldRevalidateFunctionArgs) {
|
}: ShouldRevalidateFunctionArgs) {
|
||||||
|
if (actionResult?.ok) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return currentParams.id !== nextParams.id
|
return currentParams.id !== nextParams.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user