π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: check validity
Nevo Davide5947034ab24
diff --git a/apps/frontend/src/app/(provider)/provider/[p]/bridge.tsx b/apps/frontend/src/app/(provider)/provider/[p]/bridge.tsxindex 8b713bb92..0080cf235 100644--- a/apps/frontend/src/app/(provider)/provider/[p]/bridge.tsx+++ b/apps/frontend/src/app/(provider)/provider/[p]/bridge.tsx@@ -11,6 +11,11 @@ type InitPayload = {value?: Record<string, unknown>;errors?: string[];integration?: ProviderPreviewProps['integration'];+ /**+ * Per-post media (outer array = thread entries, inner = media items).+ * Passed to the provider's `checkValidity` function during validation.+ */+ posts?: Array<Array<{ path: string; thumbnail?: string }>>;};declare global {@@ -49,6 +54,7 @@ export const ProviderPreviewBridge: FC<{ provider: string }> = ({value={init.value}errors={init.errors}integration={init.integration}+ posts={init.posts}controlRef={controlRef}/>);diff --git a/apps/frontend/src/components/new-launch/providers/high.order.provider.tsx b/apps/frontend/src/components/new-launch/providers/high.order.provider.tsxindex b66c76b68..b1f57b0e8 100644--- a/apps/frontend/src/components/new-launch/providers/high.order.provider.tsx+++ b/apps/frontend/src/components/new-launch/providers/high.order.provider.tsx@@ -363,6 +363,7 @@ export const withProvider = function <T extends object>(params: {dto,postComment,maximumCharacters,+ checkValidity,};return Wrapped;@@ -377,6 +378,11 @@ export const getProviderSettingsMeta = (component: unknown) => {dto?: any;postComment: PostComment;maximumCharacters?: number | ((settings: any) => number);+ checkValidity?: (+ value: Array<Array<{ path: string; thumbnail?: string }>>,+ settings: any,+ additionalSettings: any+ ) => Promise<string | true>;}| undefined;};diff --git a/apps/frontend/src/components/provider-preview/preview.provider.component.tsx b/apps/frontend/src/components/provider-preview/preview.provider.component.tsxindex 05bf7124c..f5ed2556a 100644--- a/apps/frontend/src/components/provider-preview/preview.provider.component.tsx+++ b/apps/frontend/src/components/provider-preview/preview.provider.component.tsx@@ -42,6 +42,11 @@ export type ProviderPreviewProps = {* or `value[0].image` β pass what you have, leave the rest to defaults.*/integration?: Partial<MockIntegration>;+ /**+ * Per-post media (outer array = thread entries, inner = media items).+ * Forwarded to the provider's `checkValidity` during validate().+ */+ posts?: Array<Array<{ path: string; thumbnail?: string }>>;/*** Imperative handle populated on mount. The parent calls* `controlRef.current?.validate()` / `.getValues()` to pull state on demand.@@ -102,6 +107,7 @@ export const ProviderPreviewComponent: FC<ProviderPreviewProps> = ({onChange,errors,integration,+ posts,controlRef,}) => {const meta = useMemo(() => {@@ -125,17 +131,38 @@ export const ProviderPreviewComponent: FC<ProviderPreviewProps> = ({getValues: () => form.getValues() as Record<string, unknown>,validate: async () => {const isValid = await form.trigger(undefined, { shouldFocus: false });+ const errs = flattenFormErrors(form.formState.errors);+ let customError: string | true = true;+ if (meta?.checkValidity) {+ try {+ const additional = (integration?.additionalSettings as+ | string+ | undefined) ?? '[]';+ const additionalSettings =+ typeof additional === 'string'+ ? JSON.parse(additional || '[]')+ : additional;+ customError = await meta.checkValidity(+ posts ?? [],+ form.getValues(),+ additionalSettings,+ );+ } catch (e: any) {+ customError = e?.message ?? 'checkValidity threw';+ }+ }+ if (customError !== true) errs.push(customError);return {- isValid,+ isValid: isValid && customError === true,value: form.getValues() as Record<string, unknown>,- errors: flattenFormErrors(form.formState.errors),+ errors: errs,};},};return () => {if (controlRef.current) controlRef.current = null;};- }, [controlRef, form]);+ }, [controlRef, form, meta, integration, posts]);const contextValue = useMemo<IntegrationContextType>(() => ({