mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-27 12:29:41 +02:00
moved it outside
This commit is contained in:
@@ -24,56 +24,58 @@ export const SlackTokensForm = ({
|
|||||||
setPopup: (popup: { message: string; type: "error" | "success" }) => void;
|
setPopup: (popup: { message: string; type: "error" | "success" }) => void;
|
||||||
router: any;
|
router: any;
|
||||||
onValuesChange?: (values: any) => void;
|
onValuesChange?: (values: any) => void;
|
||||||
}) => (
|
}) => {
|
||||||
<Formik
|
useEffect(() => {
|
||||||
initialValues={initialValues}
|
if (onValuesChange) {
|
||||||
validationSchema={Yup.object().shape({
|
onValuesChange(initialValues);
|
||||||
bot_token: Yup.string().required(),
|
}
|
||||||
app_token: Yup.string().required(),
|
}, [initialValues]);
|
||||||
name: Yup.string().required(),
|
|
||||||
})}
|
|
||||||
onSubmit={async (values, formikHelpers) => {
|
|
||||||
formikHelpers.setSubmitting(true);
|
|
||||||
|
|
||||||
let response;
|
return (
|
||||||
if (isUpdate) {
|
<Formik
|
||||||
response = await updateSlackBot(existingSlackBotId!, values);
|
initialValues={initialValues}
|
||||||
} else {
|
validationSchema={Yup.object().shape({
|
||||||
response = await createSlackBot(values);
|
bot_token: Yup.string().required(),
|
||||||
}
|
app_token: Yup.string().required(),
|
||||||
formikHelpers.setSubmitting(false);
|
name: Yup.string().required(),
|
||||||
if (response.ok) {
|
})}
|
||||||
if (refreshSlackBot) {
|
onSubmit={async (values, formikHelpers) => {
|
||||||
refreshSlackBot();
|
formikHelpers.setSubmitting(true);
|
||||||
|
|
||||||
|
let response;
|
||||||
|
if (isUpdate) {
|
||||||
|
response = await updateSlackBot(existingSlackBotId!, values);
|
||||||
|
} else {
|
||||||
|
response = await createSlackBot(values);
|
||||||
}
|
}
|
||||||
const responseJson = await response.json();
|
formikHelpers.setSubmitting(false);
|
||||||
const botId = isUpdate ? existingSlackBotId : responseJson.id;
|
if (response.ok) {
|
||||||
setPopup({
|
if (refreshSlackBot) {
|
||||||
message: isUpdate
|
refreshSlackBot();
|
||||||
? "Successfully updated Slack Bot!"
|
}
|
||||||
: "Successfully created Slack Bot!",
|
const responseJson = await response.json();
|
||||||
type: "success",
|
const botId = isUpdate ? existingSlackBotId : responseJson.id;
|
||||||
});
|
setPopup({
|
||||||
router.push(`/admin/bots/${encodeURIComponent(botId)}`);
|
message: isUpdate
|
||||||
} else {
|
? "Successfully updated Slack Bot!"
|
||||||
const responseJson = await response.json();
|
: "Successfully created Slack Bot!",
|
||||||
const errorMsg = responseJson.detail || responseJson.message;
|
type: "success",
|
||||||
setPopup({
|
});
|
||||||
message: isUpdate
|
router.push(`/admin/bots/${encodeURIComponent(botId)}`);
|
||||||
? `Error updating Slack Bot - ${errorMsg}`
|
} else {
|
||||||
: `Error creating Slack Bot - ${errorMsg}`,
|
const responseJson = await response.json();
|
||||||
type: "error",
|
const errorMsg = responseJson.detail || responseJson.message;
|
||||||
});
|
setPopup({
|
||||||
}
|
message: isUpdate
|
||||||
}}
|
? `Error updating Slack Bot - ${errorMsg}`
|
||||||
enableReinitialize={true}
|
: `Error creating Slack Bot - ${errorMsg}`,
|
||||||
>
|
type: "error",
|
||||||
{({ isSubmitting, setFieldValue, values }) => {
|
});
|
||||||
useEffect(() => {
|
}
|
||||||
onValuesChange?.(values);
|
}}
|
||||||
}, [values, onValuesChange]);
|
enableReinitialize={true}
|
||||||
|
>
|
||||||
return (
|
{({ isSubmitting, setFieldValue, values }) => (
|
||||||
<Form className="w-full">
|
<Form className="w-full">
|
||||||
{!isUpdate && (
|
{!isUpdate && (
|
||||||
<div className="">
|
<div className="">
|
||||||
@@ -126,7 +128,7 @@ export const SlackTokensForm = ({
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
)}
|
||||||
}}
|
</Formik>
|
||||||
</Formik>
|
);
|
||||||
);
|
};
|
||||||
|
Reference in New Issue
Block a user