@payfit/unity-components
Version:
33 lines (32 loc) • 1.16 kB
JavaScript
import { AIComposerAlert as e } from "../parts/AIComposerAlert.js";
import { useAIKitFormContext as t } from "../../../hooks/ai-kit-form-context.js";
import { useTanstackAIComposerFormLayoutContext as n } from "./TanstackAIComposerForm.context.js";
import { jsx as r } from "react/jsx-runtime";
//#region src/modules/ai-kit/components/ai-composer/form/TanstackAIComposerAlert.tsx
var i = (e) => {
if (typeof e == "object" && e && "message" in e) {
let { message: t } = e;
if (typeof t == "string") return t;
}
return typeof e == "string" ? e : String(e);
}, a = ({ field: a, ...o }) => {
let s = t(), { getAlertId: c } = n();
return /* @__PURE__ */ r(s.Subscribe, {
selector: (e) => ({
fieldMeta: e.fieldMeta[a],
submissionAttempts: e.submissionAttempts
}),
children: ({ fieldMeta: t, submissionAttempts: n }) => {
let s = t?.errors ?? [];
return t !== void 0 && !t.isValid && s.length > 0 && (t.isTouched || n > 0) ? /* @__PURE__ */ r(e, {
...o,
id: c(a),
variant: "error",
children: i(s[0])
}) : null;
}
});
};
a.displayName = "TanstackAIComposerAlert";
//#endregion
export { a as TanstackAIComposerAlert };