update block
This commit is contained in:
@@ -171,7 +171,7 @@ def enroll_now(enrollment: Enrollment, context: Context):
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
pk='SUBSCRIPTION#FROZEN',
|
||||
sk=f'ORG#{org.id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
@@ -288,7 +288,7 @@ def enroll_later(enrollment: Enrollment, context: Context):
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
pk='SUBSCRIPTION#FROZEN',
|
||||
sk=f'ORG#{org.id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
|
||||
@@ -45,8 +45,8 @@ def get_org(org_id: str):
|
||||
+ SortKey('METADATA#ADDRESS', rename_key='address')
|
||||
+ SortKey('METADATA#SUBSCRIPTION', rename_key='subscription')
|
||||
+ KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
pk='SUBSCRIPTION#FROZEN',
|
||||
sk=SortKey(f'ORG#{org_id}'),
|
||||
rename_key='subscription_freeze',
|
||||
rename_key='subscription_frozen',
|
||||
)
|
||||
)
|
||||
|
||||
@@ -31,6 +31,7 @@ def add(
|
||||
name: Annotated[str, Body(embed=True)],
|
||||
billing_day: Annotated[int, Body(embed=True, ge=1, le=31)],
|
||||
payment_method: Annotated[PaymentMethod, Body(embed=True)],
|
||||
subscription_frozen: Annotated[bool, Body(embed=True)] = False,
|
||||
):
|
||||
now_ = now()
|
||||
|
||||
@@ -71,6 +72,15 @@ def add(
|
||||
exc_cls=SubscriptionConflictError,
|
||||
)
|
||||
|
||||
if subscription_frozen:
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'SUBSCRIPTION#FROZEN',
|
||||
'sk': f'ORG#{org_id}',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
@@ -100,19 +110,19 @@ def edit(
|
||||
':now': now_,
|
||||
},
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=OrgNotFoundError,
|
||||
exc_cls=SubscriptionRequiredError,
|
||||
)
|
||||
|
||||
if subscription_frozen:
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'SUBSCRIPTION#FREEZE',
|
||||
'id': 'SUBSCRIPTION#FROZEN',
|
||||
'sk': f'ORG#{org_id}',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
else:
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION#FREEZE', f'ORG#{org_id}'))
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION#FROZEN', f'ORG#{org_id}'))
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
@@ -133,6 +143,6 @@ def remove(org_id: str):
|
||||
)
|
||||
transact.delete(key=KeyPair(org_id, 'METADATA#SUBSCRIPTION'))
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION', f'ORG#{org_id}'))
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION#FREEZE', f'ORG#{org_id}'))
|
||||
transact.delete(key=KeyPair('SUBSCRIPTION#FROZEN', f'ORG#{org_id}'))
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.NO_CONTENT)
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
from http import HTTPMethod, HTTPStatus
|
||||
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
|
||||
from ...conftest import HttpApiProxy, LambdaContext
|
||||
|
||||
|
||||
def test_address(
|
||||
app,
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/cJtK9SsnJhKPyxESe7g3DG/address',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
@@ -5,6 +5,22 @@ from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
from ...conftest import HttpApiProxy, LambdaContext
|
||||
|
||||
|
||||
def test_get_scheduled(
|
||||
app,
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/cJtK9SsnJhKPyxESe7g3DG/enrollments/scheduled',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
|
||||
def test_scheduled_proceed(
|
||||
app,
|
||||
seeds,
|
||||
|
||||
@@ -17,7 +17,7 @@ def test_subscription(
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/2a8963fc-4694-4fe2-953a-316d1b10f1f5',
|
||||
raw_path='/orgs/e63a579a-4719-4d64-816f-f1650ca73753',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
@@ -32,13 +32,13 @@ def test_add_subscription(
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
org_id = 'f6000f79-6e5c-49a0-952f-3bda330ef278'
|
||||
org_id = 'e63a579a-4719-4d64-816f-f1650ca73753'
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path=f'/orgs/{org_id}/subscription',
|
||||
method=HTTPMethod.POST,
|
||||
body={
|
||||
'name': 'Banco do Brasil',
|
||||
'name': 'pytest subscribed',
|
||||
'billing_day': 1,
|
||||
'payment_method': 'MANUAL',
|
||||
},
|
||||
@@ -55,4 +55,4 @@ def test_add_subscription(
|
||||
|
||||
assert r['metadata']['billing_day'] == 1
|
||||
assert r['metadata']['payment_method'] == 'MANUAL'
|
||||
assert r['subscription']['name'] == 'Banco do Brasil'
|
||||
assert r['subscription']['name'] == 'pytest subscribed'
|
||||
|
||||
@@ -15,14 +15,15 @@ def test_get_org(
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/2a8963fc-4694-4fe2-953a-316d1b10f1f5',
|
||||
raw_path='/orgs/7362ce9e-9dad-4483-a28b-fff4034a17a5',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
body = json.loads(r['body'])
|
||||
|
||||
assert 'subscription_freeze' in body
|
||||
assert 'address' in body
|
||||
assert 'subscription_frozen' in body
|
||||
|
||||
|
||||
def test_add_org(
|
||||
@@ -93,19 +94,3 @@ def test_revoke(
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.NO_CONTENT
|
||||
|
||||
|
||||
def test_get_scheduled(
|
||||
app,
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/1234/enrollments/scheduled',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Users
|
||||
{"id": "213a6682-2c59-4404-9189-12eec0a846d4", "sk": "orgs#f6000f79-6e5c-49a0-952f-3bda330ef278", "name": "Banco do Brasil", "cnpj": "00000000000191"}
|
||||
// Users
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "0", "name": "Sérgio R Siqueira", "email": "sergio@somosbeta.com.br", "emails": ["osergiosiqueira@gmail.com", "sergio@somosbeta.combr"], "cpf": "07879819908"}
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "emails#sergio@somosbeta.com.br", "email_primary": true, "mx_record_exists": true}
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "emails#osergiosiqueira@gmail.com", "email_verified": false, "mx_record_exists": true}
|
||||
@@ -12,33 +12,42 @@
|
||||
{"id": "578ec87f-94c7-4840-8780-bb4839cc7e64", "sk": "0", "course": {"id": "af3258f0-bccf-4781-aec6-d4c618d234a7", "name": "pytest", "access_period": 180}, "user": {"id": "068b4600-cc36-4b55-b832-bb620021705a", "name": "Benjamin Burnley", "email": "burnley@breakingbenjamin.com"}}
|
||||
{"id": "9c166c5e-890f-4e77-9855-769c29aaeb2e", "sk": "0", "course": {"id": "c27d1b4f-575c-4b6b-82a1-9b91ff369e0b", "name": "pytest", "access_period": 180, "scormset": "76c75561-d972-43ef-9818-497d8fc6edbe"}, "user": {"id": "068b4600-cc36-4b55-b832-bb620021705a", "name": "Layne Staley", "email": "layne@aliceinchains.com"}}
|
||||
|
||||
// Scheduled
|
||||
{"id": "SCHEDULED#ORG#cJtK9SsnJhKPyxESe7g3DG", "sk": "2028-12-16T00:00:00-03:06#981ddaa78ffaf9a1074ab1169893f45d", "org_name": "Beta Educação", "scheduled_at": "2025-12-15T17:09:39.398009-03:00", "user": { "name": "Maitê Laurenti Siqueira", "cpf": "02186829991", "id": "87606a7f-de56-4198-a91d-b6967499d382", "email": "osergiosiqueira+maite@gmail.com" }, "ttl": 1765854360, "subscription_billing_day": 5, "created_by": { "name": "Sérgio Rafael de Siqueira", "id": "5OxmMjL-ujoR5IMGegQz" }, "course": { "name": "Reciclagem em NR-10 Básico (20 horas)", "id": "c01ec8a2-0359-4351-befb-76c3577339e0", "access_period": 360}}
|
||||
|
||||
// Orgs
|
||||
// Seeds for Org
|
||||
{"id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5", "sk": "0", "name": "pytest", "cnpj": "04978826000180"}
|
||||
{"id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5", "sk": "METADATA#SUBSCRIPTION", "billing_day": 6}
|
||||
{"id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5", "sk": "METADATA#PAYMENT_POLICY", "due_days": 30, "created_at": "2025-07-15T15:04:36.369323-03:00"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#2a8963fc-4694-4fe2-953a-316d1b10f1f5"}
|
||||
{"id": "cnpj", "sk": "04978826000180", "org_id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5"}
|
||||
|
||||
// Seeds for Org
|
||||
{"id": "f6000f79-6e5c-49a0-952f-3bda330ef278", "sk": "0", "name": "Banco do Brasil", "cnpj": "00000000000191"}
|
||||
|
||||
// Org admins
|
||||
{"id": "f6000f79-6e5c-49a0-952f-3bda330ef278", "sk": "admins#15bacf02-1535-4bee-9022-19d106fd7518", "name": "Chester Bennington", "email": "chester@linkinpark.com"}
|
||||
|
||||
{"id": "orgmembers#f6000f79-6e5c-49a0-952f-3bda330ef278", "sk": "15bacf02-1535-4bee-9022-19d106fd7518"}
|
||||
|
||||
// Seeds for Org
|
||||
{"id": "cJtK9SsnJhKPyxESe7g3DG", "sk": "0", "name": "Beta Educação", "cnpj": "15608435000190"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#cJtK9SsnJhKPyxESe7g3DG"}
|
||||
{"id": "SCHEDULED#ORG#cJtK9SsnJhKPyxESe7g3DG", "sk": "2028-12-16T00:00:00-03:06#981ddaa78ffaf9a1074ab1169893f45d", "org_name": "Beta Educação", "scheduled_at": "2025-12-15T17:09:39.398009-03:00", "user": { "name": "Maitê Laurenti Siqueira", "cpf": "02186829991", "id": "87606a7f-de56-4198-a91d-b6967499d382", "email": "osergiosiqueira+maite@gmail.com" }, "ttl": 1765854360, "subscription_billing_day": 5, "created_by": { "name": "Sérgio Rafael de Siqueira", "id": "5OxmMjL-ujoR5IMGegQz" }, "course": { "name": "Reciclagem em NR-10 Básico (20 horas)", "id": "c01ec8a2-0359-4351-befb-76c3577339e0", "access_period": 360}}
|
||||
|
||||
// Seeds for Org
|
||||
// file: tests/routes/orgs/test_subscription.py
|
||||
{"id": "e63a579a-4719-4d64-816f-f1650ca73753", "sk": "0", "name": "pytest", "cnpj": "89329353000143"}
|
||||
{"id": "cnpj", "sk": "89329353000143", "org_id": "f6000f79-6e5c-49a0-952f-3bda330ef278"}
|
||||
|
||||
// Seeds for Org with subscription
|
||||
// file: tests/routes/test_orgs.py::test_get_org
|
||||
{"id": "7362ce9e-9dad-4483-a28b-fff4034a17a5", "sk": "METADATA#ADDRESS", "state": "SC", "postcode": "88101001", "address1": "Avenida Presidente Kennedy", "city": "São José", "address2": "1", "neighborhood": "Campinas"}
|
||||
{"id": "SUBSCRIPTION#FROZEN", "sk": "ORG#7362ce9e-9dad-4483-a28b-fff4034a17a5", "created_at": "2025-12-24T00:05:27-03:00"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#7362ce9e-9dad-4483-a28b-fff4034a17a5", "created_at": "2025-12-24T00:05:27-03:00"}
|
||||
|
||||
|
||||
// Seeds for Order
|
||||
// file: tests/routes/orders/test_payment_retries.py
|
||||
{"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "0", "installments": 3, "status": "PENDING"}
|
||||
{"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "INVOICE", "invoice_id": "123"}
|
||||
{"id": "4b23f6f5-5377-476b-b1de-79427c0295f6", "sk": "TRANSACTION#STATS", "last_attempt_succeeded": false}
|
||||
|
||||
// Indicies
|
||||
// CNPJs
|
||||
{"id": "cnpj", "sk": "04978826000180", "org_id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5"}
|
||||
{"id": "cnpj", "sk": "00000000000191", "org_id": "6000f79-6e5c-49a0-952f-3bda330ef278"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#2a8963fc-4694-4fe2-953a-316d1b10f1f5"}
|
||||
{"id": "SUBSCRIPTION", "sk": "ORG#cJtK9SsnJhKPyxESe7g3DG"}
|
||||
{"id": "SUBSCRIPTION#FREEZE", "sk": "ORG#2a8963fc-4694-4fe2-953a-316d1b10f1f5", "created_at": "2025-12-24T00:05:27-03:00"}
|
||||
|
||||
// CPFs
|
||||
{"id": "cpf", "sk": "07879819908", "user_id": "15bacf02-1535-4bee-9022-19d106fd7518"}
|
||||
|
||||
@@ -66,7 +66,7 @@ export const workspaceMiddleware = async (
|
||||
workspaces,
|
||||
subscription: org?.['subscription'] || null,
|
||||
address: org?.['address'] || null,
|
||||
blocked: 'subscription_freeze' in org
|
||||
blocked: 'subscription_frozen' in org
|
||||
})
|
||||
|
||||
return await next()
|
||||
|
||||
@@ -127,7 +127,7 @@ export async function action({ params, request, context }: Route.ActionArgs) {
|
||||
})
|
||||
|
||||
const data = (await r.json()) as { sk: string }
|
||||
return redirect(`/${params.orgid}/enrollments/${data.sk}/submitted`)
|
||||
return redirect(`/${org_id}/enrollments/${data.sk}/submitted`)
|
||||
}
|
||||
|
||||
export default function Route({
|
||||
|
||||
@@ -5,8 +5,10 @@ import valid from 'card-validator'
|
||||
import { ExternalLinkIcon, PencilIcon, SearchIcon } from 'lucide-react'
|
||||
import { Controller, useForm } from 'react-hook-form'
|
||||
import { PatternFormat } from 'react-number-format'
|
||||
import { useParams } from 'react-router'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { useWizard } from '@/components/wizard'
|
||||
import { Abbr } from '@repo/ui/components/abbr'
|
||||
import { Currency } from '@repo/ui/components/currency'
|
||||
import { Button } from '@repo/ui/components/ui/button'
|
||||
@@ -20,6 +22,28 @@ import {
|
||||
DialogTitle,
|
||||
DialogTrigger
|
||||
} from '@repo/ui/components/ui/dialog'
|
||||
import {
|
||||
Empty,
|
||||
EmptyContent,
|
||||
EmptyDescription,
|
||||
EmptyHeader,
|
||||
EmptyTitle
|
||||
} from '@repo/ui/components/ui/empty'
|
||||
import {
|
||||
Field,
|
||||
FieldDescription,
|
||||
FieldError,
|
||||
FieldGroup,
|
||||
FieldLabel,
|
||||
FieldSet
|
||||
} from '@repo/ui/components/ui/field'
|
||||
import { Input } from '@repo/ui/components/ui/input'
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupAddon,
|
||||
InputGroupButton,
|
||||
InputGroupInput
|
||||
} from '@repo/ui/components/ui/input-group'
|
||||
import {
|
||||
Item,
|
||||
ItemActions,
|
||||
@@ -42,31 +66,6 @@ import {
|
||||
} from '@repo/ui/components/ui/table'
|
||||
import { paymentMethods } from '@repo/ui/routes/orders/data'
|
||||
|
||||
import { useWizard } from '@/components/wizard'
|
||||
import {
|
||||
Field,
|
||||
FieldDescription,
|
||||
FieldError,
|
||||
FieldGroup,
|
||||
FieldLabel,
|
||||
FieldSet
|
||||
} from '@repo/ui/components/ui/field'
|
||||
import { Input } from '@repo/ui/components/ui/input'
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupAddon,
|
||||
InputGroupButton,
|
||||
InputGroupInput
|
||||
} from '@repo/ui/components/ui/input-group'
|
||||
|
||||
import {
|
||||
Empty,
|
||||
EmptyContent,
|
||||
EmptyDescription,
|
||||
EmptyHeader,
|
||||
EmptyTitle
|
||||
} from '@repo/ui/components/ui/empty'
|
||||
import { useParams } from 'react-router'
|
||||
import { useWizardStore } from './store'
|
||||
|
||||
type ReviewProps = {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Route } from './+types/route'
|
||||
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { PatternFormat } from 'react-number-format'
|
||||
import { useOutletContext } from 'react-router'
|
||||
|
||||
import { Button } from '@repo/ui/components/ui/button'
|
||||
@@ -22,10 +23,12 @@ import {
|
||||
} from '@repo/ui/components/ui/form'
|
||||
import { Input } from '@repo/ui/components/ui/input'
|
||||
|
||||
import type { Org } from '../_app.orgs.$id/data'
|
||||
|
||||
export default function Route({}: Route.ComponentProps) {
|
||||
const { org } = useOutletContext()
|
||||
const { org } = useOutletContext() as { org: Org }
|
||||
const form = useForm({ defaultValues: org })
|
||||
const { handleSubmit, formState } = form
|
||||
const { handleSubmit, control } = form
|
||||
|
||||
const onSubmit = async () => {}
|
||||
|
||||
@@ -45,7 +48,7 @@ export default function Route({}: Route.ComponentProps) {
|
||||
<CardContent className="space-y-6">
|
||||
<FieldSet disabled={true}>
|
||||
<FormField
|
||||
control={form.control}
|
||||
control={control}
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
@@ -59,7 +62,7 @@ export default function Route({}: Route.ComponentProps) {
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
control={control}
|
||||
name="email"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
@@ -73,13 +76,28 @@ export default function Route({}: Route.ComponentProps) {
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
control={control}
|
||||
name="cnpj"
|
||||
render={({ field }) => (
|
||||
render={({
|
||||
field: { onChange, ref, ...field },
|
||||
fieldState
|
||||
}) => (
|
||||
<FormItem>
|
||||
<FormLabel>CNPJ</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
<PatternFormat
|
||||
id={field.name}
|
||||
format="##.###.###/####-##"
|
||||
mask="_"
|
||||
placeholder="__.___.___/____-__"
|
||||
customInput={Input}
|
||||
getInputRef={ref}
|
||||
aria-invalid={fieldState.invalid}
|
||||
onValueChange={({ value }) => {
|
||||
onChange(value)
|
||||
}}
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
@@ -1,11 +1,165 @@
|
||||
import type { Route } from './+types/route'
|
||||
|
||||
import { Card, CardContent } from '@repo/ui/components/ui/card'
|
||||
import { Controller, useForm } from 'react-hook-form'
|
||||
import { useOutletContext } from 'react-router'
|
||||
|
||||
import { Button } from '@repo/ui/components/ui/button'
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle
|
||||
} from '@repo/ui/components/ui/card'
|
||||
import {
|
||||
Field,
|
||||
FieldError,
|
||||
FieldGroup,
|
||||
FieldLabel,
|
||||
FieldSet
|
||||
} from '@repo/ui/components/ui/field'
|
||||
import { Input } from '@repo/ui/components/ui/input'
|
||||
|
||||
import type { Org } from '../_app.orgs.$id/data'
|
||||
|
||||
export default function Route({}: Route.ComponentProps) {
|
||||
const { org } = useOutletContext() as { org: Org }
|
||||
const { handleSubmit, control } = useForm({ defaultValues: org?.address })
|
||||
|
||||
const onSubmit = async () => {}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<Card>
|
||||
<CardContent>address</CardContent>
|
||||
<CardHeader>
|
||||
<CardTitle className="font-semibold text-lg">
|
||||
Editar endereço
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Este endereço será usado automaticamente sempre que for necessário
|
||||
informar um endereço.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="space-y-6">
|
||||
<FieldSet disabled={true}>
|
||||
<Controller
|
||||
control={control}
|
||||
name="address1"
|
||||
defaultValue=""
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor={field.name}>Endereço</FieldLabel>
|
||||
<Input
|
||||
id={field.name}
|
||||
aria-invalid={fieldState.invalid}
|
||||
{...field}
|
||||
/>
|
||||
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
name="address2"
|
||||
defaultValue=""
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor={field.name}>
|
||||
Complemento{' '}
|
||||
<span className="text-muted-foreground">(opcional)</span>
|
||||
</FieldLabel>
|
||||
<Input
|
||||
id={field.name}
|
||||
aria-invalid={fieldState.invalid}
|
||||
{...field}
|
||||
/>
|
||||
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FieldGroup className="grid grid-cols-3">
|
||||
{/* Neighborhood */}
|
||||
<Controller
|
||||
control={control}
|
||||
name="neighborhood"
|
||||
defaultValue=""
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor={field.name}>Bairro</FieldLabel>
|
||||
<Input
|
||||
id={field.name}
|
||||
aria-invalid={fieldState.invalid}
|
||||
{...field}
|
||||
/>
|
||||
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
{/* City */}
|
||||
<Controller
|
||||
control={control}
|
||||
name="city"
|
||||
defaultValue=""
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor={field.name}>Cidade</FieldLabel>
|
||||
<Input
|
||||
id={field.name}
|
||||
aria-invalid={fieldState.invalid}
|
||||
{...field}
|
||||
/>
|
||||
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
{/* State */}
|
||||
<Controller
|
||||
control={control}
|
||||
name="state"
|
||||
defaultValue=""
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor={field.name}>Estado</FieldLabel>
|
||||
<Input
|
||||
id={field.name}
|
||||
aria-invalid={fieldState.invalid}
|
||||
{...field}
|
||||
/>
|
||||
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
className="cursor-pointer"
|
||||
// disabled={formState.isSubmitting}
|
||||
disabled={true}
|
||||
>
|
||||
Atualizar endereço
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type { Route } from './+types/route'
|
||||
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { useOutletContext } from 'react-router'
|
||||
import { useFetcher, useOutletContext } from 'react-router'
|
||||
import { z } from 'zod'
|
||||
|
||||
import { Button } from '@repo/ui/components/ui/button'
|
||||
import {
|
||||
@@ -11,6 +13,7 @@ import {
|
||||
CardHeader,
|
||||
CardTitle
|
||||
} from '@repo/ui/components/ui/card'
|
||||
import { Checkbox } from '@repo/ui/components/ui/checkbox'
|
||||
import { FieldGroup, FieldLegend, FieldSet } from '@repo/ui/components/ui/field'
|
||||
import {
|
||||
Form,
|
||||
@@ -27,23 +30,87 @@ import {
|
||||
NativeSelectOption
|
||||
} from '@repo/ui/components/ui/native-select'
|
||||
import { RadioGroup, RadioGroupItem } from '@repo/ui/components/ui/radio-group'
|
||||
import { Spinner } from '@repo/ui/components/ui/spinner'
|
||||
import { HttpMethod, request as req } from '@repo/util/request'
|
||||
|
||||
import type { Org, Subscription } from '../_app.orgs.$id/data'
|
||||
|
||||
const formSchema = z.object({
|
||||
plan: z.enum(['NOTHING', 'FLEXIVEL']),
|
||||
billing_day: z.number({ error: 'Deve estar entre 1 e 31' }).min(1).max(31),
|
||||
payment_method: z.enum(['BANK_SLIP', 'MANUAL'], {
|
||||
error: 'Selecione uma opção'
|
||||
}),
|
||||
subscription_frozen: z.boolean().optional()
|
||||
})
|
||||
|
||||
type Schema = Subscription & z.infer<typeof formSchema>
|
||||
|
||||
export async function action({ params, request, context }: Route.ActionArgs) {
|
||||
const method = request.method
|
||||
|
||||
if (method === 'DELETE') {
|
||||
await req({
|
||||
url: `orgs/${params.id}/subscription`,
|
||||
method: HttpMethod.DELETE,
|
||||
request,
|
||||
context
|
||||
})
|
||||
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
const r = await req({
|
||||
url: `orgs/${params.id}/subscription`,
|
||||
headers: new Headers({ 'Content-Type': 'application/json' }),
|
||||
method: method as HttpMethod,
|
||||
body: JSON.stringify(await request.json()),
|
||||
request,
|
||||
context
|
||||
})
|
||||
|
||||
console.log(r)
|
||||
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
export default function Route({}: Route.ComponentProps) {
|
||||
const { org } = useOutletContext()
|
||||
const form = useForm({ defaultValues: org?.subscription })
|
||||
const { handleSubmit, formState } = form
|
||||
const fetcher = useFetcher()
|
||||
const { org } = useOutletContext() as { org: Org }
|
||||
const subscribed = !!org?.subscription
|
||||
const form = useForm<Schema>({
|
||||
defaultValues: {
|
||||
plan: subscribed ? 'FLEXIVEL' : 'NOTHING',
|
||||
...org?.subscription
|
||||
},
|
||||
resolver: zodResolver(formSchema)
|
||||
})
|
||||
const { handleSubmit, formState, watch } = form
|
||||
const plan = watch('plan')
|
||||
|
||||
const onSubmit = async (data) => {
|
||||
console.log(data)
|
||||
const onSubmit = async ({ plan, ...data }: Schema) => {
|
||||
if (plan === 'NOTHING') {
|
||||
fetcher.submit(null, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
fetcher.submit(JSON.stringify({ name: org.name, ...data }), {
|
||||
method: subscribed ? 'PUT' : 'POST',
|
||||
encType: 'application/json'
|
||||
})
|
||||
}
|
||||
|
||||
console.log(org)
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="font-semibold text-lg">
|
||||
Escolha seu plano
|
||||
Escolha um plano
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Escolha o plano que será utilizado para configurar o funcionamento
|
||||
@@ -52,33 +119,57 @@ export default function Route({}: Route.ComponentProps) {
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="space-y-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="plan"
|
||||
render={({ field: { value, onChange } }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup
|
||||
defaultValue="none"
|
||||
className="lg:grid-cols-2 *:border *:p-4 *:rounded-lg *:cursor-pointer
|
||||
defaultValue={value}
|
||||
onValueChange={onChange}
|
||||
className="lg:grid-cols-2 grid gap-4
|
||||
*:border *:p-4 *:rounded-lg *:cursor-pointer
|
||||
*:has-[[aria-checked=true]]:bg-muted"
|
||||
>
|
||||
<Label className="flex items-center gap-3">
|
||||
<RadioGroupItem value="none" />
|
||||
<div>Nenhum</div>
|
||||
<RadioGroupItem value="NOTHING" />
|
||||
<div className="font-medium">Sem plano</div>
|
||||
</Label>
|
||||
|
||||
<Label className="flex items-center gap-3">
|
||||
<RadioGroupItem value="flexivel" />
|
||||
<div>Flexível</div>
|
||||
<RadioGroupItem value="FLEXIVEL" />
|
||||
<div className="font-medium">Flexível</div>
|
||||
</Label>
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
|
||||
<FieldSet className="border rounded-lg p-6 bg-accent/10">
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FieldSet
|
||||
className="border rounded-lg p-6 bg-accent/10"
|
||||
disabled={plan === 'NOTHING'}
|
||||
>
|
||||
<FieldLegend className="mb-0">Configurações do plano</FieldLegend>
|
||||
|
||||
<FieldGroup>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="billing_day"
|
||||
render={({ field }) => (
|
||||
render={({ field: { onChange, ...field } }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Dia para faturar</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" min={1} max={30} {...field} />
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
max={30}
|
||||
onChange={(e) => onChange(Number(e.target.value))}
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -93,6 +184,9 @@ export default function Route({}: Route.ComponentProps) {
|
||||
<FormLabel>Forma de pagamento</FormLabel>
|
||||
<FormControl>
|
||||
<NativeSelect {...field}>
|
||||
<NativeSelectOption value="">
|
||||
Selecione
|
||||
</NativeSelectOption>
|
||||
<NativeSelectOption value="BANK_SLIP">
|
||||
Boleto bancário
|
||||
</NativeSelectOption>
|
||||
@@ -105,6 +199,26 @@ export default function Route({}: Route.ComponentProps) {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="subscription_frozen"
|
||||
defaultValue={false}
|
||||
render={({ field: { onChange, value, ...field } }) => (
|
||||
<FormItem className="flex items-center gap-2">
|
||||
<FormControl>
|
||||
<Checkbox
|
||||
checked={value}
|
||||
onCheckedChange={onChange}
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormLabel>
|
||||
Suspender temporariamente o funcionamento do plano
|
||||
</FormLabel>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
|
||||
@@ -113,6 +227,7 @@ export default function Route({}: Route.ComponentProps) {
|
||||
className="cursor-pointer"
|
||||
disabled={formState.isSubmitting}
|
||||
>
|
||||
{formState.isSubmitting ? <Spinner /> : null}
|
||||
Atualizar plano
|
||||
</Button>
|
||||
</CardContent>
|
||||
|
||||
@@ -21,10 +21,12 @@ import { initials } from '@repo/ui/lib/utils'
|
||||
import { request as req } from '@repo/util/request'
|
||||
import { BadgeCheckIcon } from 'lucide-react'
|
||||
|
||||
import type { Org } from './data'
|
||||
|
||||
const links = [
|
||||
{ to: '', title: 'Perfil', end: true },
|
||||
{ to: 'subscription', title: 'Plano' },
|
||||
{ to: 'address', title: 'Endereço' }
|
||||
{ to: 'address', title: 'Endereço' },
|
||||
{ to: 'subscription', title: 'Plano' }
|
||||
]
|
||||
|
||||
export function meta() {
|
||||
@@ -46,7 +48,9 @@ export async function loader({ params, request, context }: Route.LoaderArgs) {
|
||||
throw new Response(null, { status: r.status })
|
||||
}
|
||||
|
||||
return { org: await r.json() } as { org: any }
|
||||
return { org: await r.json() } as {
|
||||
org: Org
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldRevalidate({
|
||||
|
||||
@@ -194,7 +194,7 @@ def enroll(
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
pk='SUBSCRIPTION#FROZEN',
|
||||
sk=f'ORG#{org_id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
@@ -245,7 +245,7 @@ def enroll(
|
||||
},
|
||||
)
|
||||
|
||||
# The deduplication window can be recalculated based on user settings.
|
||||
# The deduplication window can be recalculated based on settings.
|
||||
if deduplication_window:
|
||||
transact.put(
|
||||
item={
|
||||
|
||||
Reference in New Issue
Block a user