2022-05-14 22:35:51 +00:00
|
|
|
import { useState } from "react";
|
2022-06-08 22:33:19 +00:00
|
|
|
import { Form, useActionData, useLoaderData, useTransition } from "@remix-run/react";
|
2022-05-14 22:35:51 +00:00
|
|
|
import { IoHelpCircle } from "react-icons/io5";
|
|
|
|
|
2022-06-08 22:33:19 +00:00
|
|
|
import type { PhoneSettingsLoaderData } from "~/features/settings/loaders/phone";
|
|
|
|
import type { SetTwilioCredentialsActionData } from "~/features/settings/actions/phone";
|
2022-05-14 22:35:51 +00:00
|
|
|
import HelpModal from "./help-modal";
|
|
|
|
import SettingsSection from "../settings-section";
|
|
|
|
import useSession from "~/features/core/hooks/use-session";
|
2022-06-08 22:33:19 +00:00
|
|
|
import Alert from "~/features/core/components/alert";
|
|
|
|
import LabeledTextField from "~/features/core/components/labeled-text-field";
|
|
|
|
import Button from "~/features/settings/components/button";
|
2022-05-14 22:35:51 +00:00
|
|
|
|
|
|
|
export default function TwilioConnect() {
|
2022-06-08 22:33:19 +00:00
|
|
|
const { twilio } = useSession();
|
2023-04-29 16:30:07 +00:00
|
|
|
console.log("twilio", twilio);
|
2022-05-14 22:35:51 +00:00
|
|
|
const [isHelpModalOpen, setIsHelpModalOpen] = useState(false);
|
2022-06-08 22:33:19 +00:00
|
|
|
const transition = useTransition();
|
2023-04-29 16:30:07 +00:00
|
|
|
const actionData = useActionData<any>()
|
|
|
|
?.setTwilioCredentials as SetTwilioCredentialsActionData["setTwilioCredentials"];
|
2022-06-08 22:33:19 +00:00
|
|
|
const { accountSid, authToken } = useLoaderData<PhoneSettingsLoaderData>();
|
|
|
|
|
|
|
|
const topErrorMessage = actionData?.errors?.general;
|
|
|
|
const isError = typeof topErrorMessage !== "undefined";
|
2022-06-11 00:09:37 +00:00
|
|
|
const isCurrentFormTransition = transition.submission?.formData.get("_action") === "setTwilioCredentials";
|
2022-06-08 22:33:19 +00:00
|
|
|
const isSubmitting = isCurrentFormTransition && transition.state === "submitting";
|
2022-05-14 22:35:51 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-06-08 22:33:19 +00:00
|
|
|
<Form method="post">
|
|
|
|
<SettingsSection
|
|
|
|
className="flex flex-col relative"
|
|
|
|
footer={
|
|
|
|
<div className="px-4 py-3 bg-gray-50 text-right text-sm font-medium sm:px-6">
|
|
|
|
<Button tabIndex={3} variant="default" type="submit" isDisabled={isSubmitting}>
|
|
|
|
Save
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
2022-05-14 22:35:51 +00:00
|
|
|
<button onClick={() => setIsHelpModalOpen(true)} className="absolute top-2 right-2">
|
|
|
|
<IoHelpCircle className="w-6 h-6 text-primary-700" />
|
|
|
|
</button>
|
2022-05-17 23:54:06 +00:00
|
|
|
<article className="mb-6">
|
2022-06-26 11:52:36 +00:00
|
|
|
<p>
|
|
|
|
To connect your Twilio Account you will need to provide us your Twilio account SID and auth
|
|
|
|
token.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Both values can be found on your{" "}
|
|
|
|
<a href="https://www.twilio.com/user/account/settings">Twilio account page</a>.
|
|
|
|
</p>
|
2022-05-14 22:35:51 +00:00
|
|
|
</article>
|
|
|
|
|
2023-04-29 16:30:07 +00:00
|
|
|
{twilio != null ? (
|
2022-05-14 22:35:51 +00:00
|
|
|
<p className="text-green-700">✓ Your Twilio account is connected to Shellphone.</p>
|
2022-06-08 22:33:19 +00:00
|
|
|
) : null}
|
|
|
|
|
|
|
|
{isError ? (
|
|
|
|
<div className="mb-8">
|
|
|
|
<Alert title="Oops, there was an issue" message={topErrorMessage} variant="error" />
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
<LabeledTextField
|
|
|
|
name="twilioAccountSid"
|
|
|
|
label="Account SID"
|
|
|
|
type="text"
|
|
|
|
tabIndex={1}
|
|
|
|
error={actionData?.errors?.twilioAccountSid}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
defaultValue={accountSid}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<LabeledTextField
|
|
|
|
name="twilioAuthToken"
|
|
|
|
label="Auth Token"
|
|
|
|
type="password"
|
|
|
|
tabIndex={2}
|
|
|
|
error={actionData?.errors?.twilioAuthToken}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
autoComplete="off"
|
|
|
|
defaultValue={authToken}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<input type="hidden" name="_action" value="setTwilioCredentials" />
|
|
|
|
</SettingsSection>
|
|
|
|
</Form>
|
2022-05-14 22:35:51 +00:00
|
|
|
|
|
|
|
<HelpModal closeModal={() => setIsHelpModalOpen(false)} isHelpModalOpen={isHelpModalOpen} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|