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();
|
2022-05-14 22:35:51 +00:00
|
|
|
const [isHelpModalOpen, setIsHelpModalOpen] = useState(false);
|
2022-06-08 22:33:19 +00:00
|
|
|
const transition = useTransition();
|
|
|
|
const actionData = useActionData<SetTwilioCredentialsActionData>()?.setTwilioCredentials;
|
|
|
|
const { accountSid, authToken } = useLoaderData<PhoneSettingsLoaderData>();
|
|
|
|
|
|
|
|
const topErrorMessage = actionData?.errors?.general;
|
|
|
|
const isError = typeof topErrorMessage !== "undefined";
|
|
|
|
const isCurrentFormTransition = transition.submission?.formData.get("_action") === "changePassword";
|
|
|
|
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-08 22:33:19 +00:00
|
|
|
Shellphone needs some informations about your Twilio account to securely use your phone numbers.
|
2022-05-14 22:35:51 +00:00
|
|
|
</article>
|
|
|
|
|
2022-06-08 22:33:19 +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} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|