@@ -7,21 +7,30 @@ import {
77 useTypedActionData ,
88 useTypedLoaderData ,
99} from "remix-typedjson" ;
10+ import {
11+ API_RATE_LIMIT_INTENT ,
12+ API_RATE_LIMIT_SAVED_VALUE ,
13+ ApiRateLimitSection ,
14+ } from "~/components/admin/backOffice/ApiRateLimitSection" ;
15+ import {
16+ handleApiRateLimitAction ,
17+ resolveEffectiveApiRateLimit ,
18+ } from "~/components/admin/backOffice/ApiRateLimitSection.server" ;
19+ import {
20+ BATCH_RATE_LIMIT_INTENT ,
21+ BATCH_RATE_LIMIT_SAVED_VALUE ,
22+ BatchRateLimitSection ,
23+ } from "~/components/admin/backOffice/BatchRateLimitSection" ;
24+ import {
25+ handleBatchRateLimitAction ,
26+ resolveEffectiveBatchRateLimit ,
27+ } from "~/components/admin/backOffice/BatchRateLimitSection.server" ;
1028import {
1129 MAX_PROJECTS_INTENT ,
1230 MAX_PROJECTS_SAVED_VALUE ,
1331 MaxProjectsSection ,
1432} from "~/components/admin/backOffice/MaxProjectsSection" ;
1533import { handleMaxProjectsAction } from "~/components/admin/backOffice/MaxProjectsSection.server" ;
16- import {
17- RATE_LIMIT_INTENT ,
18- RATE_LIMIT_SAVED_VALUE ,
19- RateLimitSection ,
20- } from "~/components/admin/backOffice/RateLimitSection" ;
21- import {
22- handleRateLimitAction ,
23- resolveEffectiveRateLimit ,
24- } from "~/components/admin/backOffice/RateLimitSection.server" ;
2534import { LinkButton } from "~/components/primitives/Buttons" ;
2635import { CopyableText } from "~/components/primitives/CopyableText" ;
2736import { Header1 } from "~/components/primitives/Headers" ;
@@ -50,6 +59,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
5059 title : true ,
5160 createdAt : true ,
5261 apiRateLimiterConfig : true ,
62+ batchRateLimitConfig : true ,
5363 maximumProjectCount : true ,
5464 } ,
5565 } ) ;
@@ -58,9 +68,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
5868 throw new Response ( null , { status : 404 } ) ;
5969 }
6070
61- const effective = resolveEffectiveRateLimit ( org . apiRateLimiterConfig ) ;
71+ const apiEffective = resolveEffectiveApiRateLimit ( org . apiRateLimiterConfig ) ;
72+ const batchEffective = resolveEffectiveBatchRateLimit (
73+ org . batchRateLimitConfig
74+ ) ;
6275
63- return typedjson ( { org, effective } ) ;
76+ return typedjson ( { org, apiEffective , batchEffective } ) ;
6477}
6578
6679export async function action ( { request, params } : ActionFunctionArgs ) {
@@ -90,16 +103,29 @@ export async function action({ request, params }: ActionFunctionArgs) {
90103 ) ;
91104 }
92105
93- if ( intent === RATE_LIMIT_INTENT ) {
94- const result = await handleRateLimitAction ( formData , orgId , user . id ) ;
106+ if ( intent === API_RATE_LIMIT_INTENT ) {
107+ const result = await handleApiRateLimitAction ( formData , orgId , user . id ) ;
95108 if ( ! result . ok ) {
96109 return typedjson (
97- { section : RATE_LIMIT_SAVED_VALUE , errors : result . errors } ,
110+ { section : API_RATE_LIMIT_SAVED_VALUE , errors : result . errors } ,
98111 { status : 400 }
99112 ) ;
100113 }
101114 return redirect (
102- `/admin/back-office/orgs/${ orgId } ?${ SAVED_QUERY_KEY } =${ RATE_LIMIT_SAVED_VALUE } `
115+ `/admin/back-office/orgs/${ orgId } ?${ SAVED_QUERY_KEY } =${ API_RATE_LIMIT_SAVED_VALUE } `
116+ ) ;
117+ }
118+
119+ if ( intent === BATCH_RATE_LIMIT_INTENT ) {
120+ const result = await handleBatchRateLimitAction ( formData , orgId , user . id ) ;
121+ if ( ! result . ok ) {
122+ return typedjson (
123+ { section : BATCH_RATE_LIMIT_SAVED_VALUE , errors : result . errors } ,
124+ { status : 400 }
125+ ) ;
126+ }
127+ return redirect (
128+ `/admin/back-office/orgs/${ orgId } ?${ SAVED_QUERY_KEY } =${ BATCH_RATE_LIMIT_SAVED_VALUE } `
103129 ) ;
104130 }
105131
@@ -110,7 +136,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
110136}
111137
112138export default function BackOfficeOrgPage ( ) {
113- const { org, effective } = useTypedLoaderData < typeof loader > ( ) ;
139+ const { org, apiEffective, batchEffective } =
140+ useTypedLoaderData < typeof loader > ( ) ;
114141 const actionData = useTypedActionData < typeof action > ( ) ;
115142 const navigation = useNavigation ( ) ;
116143 const isSubmitting = navigation . state !== "idle" ;
@@ -154,10 +181,17 @@ export default function BackOfficeOrgPage() {
154181 </ LinkButton >
155182 </ div >
156183
157- < RateLimitSection
158- effective = { effective }
159- errors = { errorSection === RATE_LIMIT_SAVED_VALUE ? errors : null }
160- savedJustNow = { savedSection === RATE_LIMIT_SAVED_VALUE }
184+ < ApiRateLimitSection
185+ effective = { apiEffective }
186+ errors = { errorSection === API_RATE_LIMIT_SAVED_VALUE ? errors : null }
187+ savedJustNow = { savedSection === API_RATE_LIMIT_SAVED_VALUE }
188+ isSubmitting = { isSubmitting }
189+ />
190+
191+ < BatchRateLimitSection
192+ effective = { batchEffective }
193+ errors = { errorSection === BATCH_RATE_LIMIT_SAVED_VALUE ? errors : null }
194+ savedJustNow = { savedSection === BATCH_RATE_LIMIT_SAVED_VALUE }
161195 isSubmitting = { isSubmitting }
162196 />
163197
0 commit comments