update prettier config

This commit is contained in:
m5r 2021-08-01 20:04:04 +08:00
parent fdf9df243b
commit 7acbca65ce
33 changed files with 65 additions and 52 deletions

View File

@ -15,7 +15,7 @@ const bodySchema = zod.object({
export default async function subscribeToNewsletter( export default async function subscribeToNewsletter(
req: BlitzApiRequest, req: BlitzApiRequest,
res: BlitzApiResponse<Response> res: BlitzApiResponse<Response>,
) { ) {
if (req.method !== "POST") { if (req.method !== "POST") {
const statusCode = 405; const statusCode = 405;

View File

@ -20,5 +20,5 @@ export default resolver.pipe(
}); });
return true; return true;
} },
); );

View File

@ -18,7 +18,7 @@ jest.mock("preview-email", () => jest.fn());
describe.skip("forgotPassword mutation", () => { describe.skip("forgotPassword mutation", () => {
it("does not throw error if user doesn't exist", async () => { it("does not throw error if user doesn't exist", async () => {
await expect( await expect(
forgotPassword({ email: "no-user@email.com" }, {} as Ctx) forgotPassword({ email: "no-user@email.com" }, {} as Ctx),
).resolves.not.toThrow(); ).resolves.not.toThrow();
}); });

View File

@ -53,21 +53,21 @@ describe.skip("resetPassword mutation", () => {
// Non-existent token // Non-existent token
await expect( await expect(
resetPassword({ token: "no-token", password: "", passwordConfirmation: "" }, mockCtx) resetPassword({ token: "no-token", password: "", passwordConfirmation: "" }, mockCtx),
).rejects.toThrowError(); ).rejects.toThrowError();
// Expired token // Expired token
await expect( await expect(
resetPassword( resetPassword(
{ token: expiredToken, password: newPassword, passwordConfirmation: newPassword }, { token: expiredToken, password: newPassword, passwordConfirmation: newPassword },
mockCtx mockCtx,
) ),
).rejects.toThrowError(); ).rejects.toThrowError();
// Good token // Good token
await resetPassword( await resetPassword(
{ token: goodToken, password: newPassword, passwordConfirmation: newPassword }, { token: goodToken, password: newPassword, passwordConfirmation: newPassword },
mockCtx mockCtx,
); );
// Delete's the token // Delete's the token
@ -77,7 +77,7 @@ describe.skip("resetPassword mutation", () => {
// Updates user's password // Updates user's password
const updatedUser = await db.user.findFirst({ where: { id: user.id } }); const updatedUser = await db.user.findFirst({ where: { id: user.id } });
expect(await SecurePassword.verify(updatedUser!.hashedPassword, newPassword)).toBe( expect(await SecurePassword.verify(updatedUser!.hashedPassword, newPassword)).toBe(
SecurePassword.VALID SecurePassword.VALID,
); );
}); });
}); });

View File

@ -52,7 +52,7 @@ export const LabeledTextField = forwardRef<HTMLInputElement, LabeledTextFieldPro
`}</style> `}</style>
</div> </div>
); );
} },
); );
export default LabeledTextField; export default LabeledTextField;

View File

@ -8,7 +8,7 @@ export default function useCustomerPhoneNumber() {
const [customerPhoneNumber] = useQuery( const [customerPhoneNumber] = useQuery(
getCurrentCustomerPhoneNumber, getCurrentCustomerPhoneNumber,
{}, {},
{ enabled: hasCompletedOnboarding } { enabled: hasCompletedOnboarding },
); );
return customerPhoneNumber; return customerPhoneNumber;

View File

@ -114,7 +114,7 @@ const ErrorBoundary = withRouter(
return this.props.children; return this.props.children;
} }
} },
); );
export default Layout; export default Layout;

View File

@ -21,7 +21,7 @@ const fetchMessagesQueue = Queue<Payload>("api/queue/fetch-messages", async ({ c
}), }),
]); ]);
const messages = [...messagesSent, ...messagesReceived].sort( const messages = [...messagesSent, ...messagesReceived].sort(
(a, b) => a.dateCreated.getTime() - b.dateCreated.getTime() (a, b) => a.dateCreated.getTime() - b.dateCreated.getTime(),
); );
await insertMessagesQueue.enqueue( await insertMessagesQueue.enqueue(
@ -31,7 +31,7 @@ const fetchMessagesQueue = Queue<Payload>("api/queue/fetch-messages", async ({ c
}, },
{ {
id: `insert-messages-${customerId}`, id: `insert-messages-${customerId}`,
} },
); );
}); });

View File

@ -46,7 +46,7 @@ const insertIncomingMessageQueue = Queue<Payload>(
sentAt: new Date(message.dateCreated), sentAt: new Date(message.dateCreated),
}, },
}); });
} },
); );
export default insertIncomingMessageQueue; export default insertIncomingMessageQueue;

View File

@ -29,7 +29,7 @@ const insertMessagesQueue = Queue<Payload>(
.sort((a, b) => a.sentAt.getTime() - b.sentAt.getTime()); .sort((a, b) => a.sentAt.getTime() - b.sentAt.getTime());
await db.message.createMany({ data: sms }); await db.message.createMany({ data: sms });
} },
); );
export default insertMessagesQueue; export default insertMessagesQueue;

View File

@ -19,7 +19,7 @@ const sendMessageQueue = Queue<Payload>(
try { try {
const message = await twilio( const message = await twilio(
customer!.accountSid!, customer!.accountSid!,
customer!.authToken! customer!.authToken!,
).messages.create({ ).messages.create({
body: content, body: content,
to, to,
@ -37,7 +37,7 @@ const sendMessageQueue = Queue<Payload>(
}, },
{ {
retry: ["1min"], retry: ["1min"],
} },
); );
export default sendMessageQueue; export default sendMessageQueue;

View File

@ -61,7 +61,7 @@ export default async function incomingMessageHandler(req: BlitzApiRequest, res:
customer.authToken, customer.authToken,
twilioSignature, twilioSignature,
url, url,
req.body req.body,
); );
if (!isRequestValid) { if (!isRequestValid) {
const statusCode = 400; const statusCode = 400;
@ -83,7 +83,7 @@ export default async function incomingMessageHandler(req: BlitzApiRequest, res:
messageSid, messageSid,
customerId: customer.id, customerId: customer.id,
}, },
{ id: messageSid } { id: messageSid },
); );
res.status(200).end(); res.status(200).end();

View File

@ -57,7 +57,7 @@ export default function Conversation() {
<div <div
className={clsx( className={clsx(
isSameNext ? "pb-1" : "pb-2", isSameNext ? "pb-1" : "pb-2",
isOutbound ? "text-right" : "text-left" isOutbound ? "text-right" : "text-left",
)} )}
> >
<span <span
@ -65,7 +65,7 @@ export default function Conversation() {
"inline-block text-left w-[fit-content] p-2 rounded-lg text-white", "inline-block text-left w-[fit-content] p-2 rounded-lg text-white",
isOutbound isOutbound
? "bg-[#3194ff] rounded-br-none" ? "bg-[#3194ff] rounded-br-none"
: "bg-black rounded-bl-none" : "bg-black rounded-bl-none",
)} )}
> >
{message.content} {message.content}

View File

@ -25,7 +25,7 @@ const NewMessageArea: FunctionComponent<Props> = ({ recipient, onSend }) => {
const sendMessageMutation = useMutation(sendMessage)[0]; const sendMessageMutation = useMutation(sendMessage)[0];
const { setQueryData: setConversationsQueryData, refetch: refetchConversations } = useQuery( const { setQueryData: setConversationsQueryData, refetch: refetchConversations } = useQuery(
getConversationsQuery, getConversationsQuery,
{} {},
)[1]; )[1];
const { const {
register, register,
@ -65,7 +65,7 @@ const NewMessageArea: FunctionComponent<Props> = ({ recipient, onSend }) => {
nextConversations[recipient] = [...nextConversations[recipient]!, message]; nextConversations[recipient] = [...nextConversations[recipient]!, message];
return nextConversations; return nextConversations;
}, },
{ refetch: false } { refetch: false },
); );
setValue("content", ""); setValue("content", "");
onSend?.(); onSend?.();

View File

@ -15,6 +15,6 @@ export default function useConversation(recipient: string) {
return conversations[recipient]!; return conversations[recipient]!;
}, },
keepPreviousData: true, keepPreviousData: true,
} },
); );
} }

View File

@ -9,6 +9,6 @@ export default function useKnownRecipients() {
select(conversations) { select(conversations) {
return Object.keys(conversations); return Object.keys(conversations);
}, },
} },
); );
} }

View File

@ -54,7 +54,7 @@ export default resolver.pipe(
}, },
{ {
id: message.id, id: message.id,
} },
); );
} },
); );

View File

@ -27,5 +27,5 @@ export default resolver.pipe(
content: decrypt(message.content, customer!.encryptionKey), content: decrypt(message.content, customer!.encryptionKey),
}; };
}); });
} },
); );

View File

@ -33,8 +33,8 @@ export default resolver.pipe(resolver.authorize(), async (_ = null, context) =>
} }
conversations = Object.fromEntries( conversations = Object.fromEntries(
Object.entries(conversations).sort( Object.entries(conversations).sort(
([, a], [, b]) => b[b.length - 1]!.sentAt.getTime() - a[a.length - 1]!.sentAt.getTime() ([, a], [, b]) => b[b.length - 1]!.sentAt.getTime() - a[a.length - 1]!.sentAt.getTime(),
) ),
); );
return conversations; return conversations;

View File

@ -37,7 +37,7 @@ const setTwilioWebhooks = Queue<Payload>(
voiceApplicationSid: twimlAppSid, voiceApplicationSid: twimlAppSid,
}), }),
]); ]);
} },
); );
export default setTwilioWebhooks; export default setTwilioWebhooks;

View File

@ -65,7 +65,7 @@ const OnboardingLayout: FunctionComponent<Props> = ({ children, currentStep, pre
key={step} key={step}
className={clsx( className={clsx(
stepIdx !== steps.length - 1 ? "pr-20 sm:pr-32" : "", stepIdx !== steps.length - 1 ? "pr-20 sm:pr-32" : "",
"relative" "relative",
)} )}
> >
{isComplete ? ( {isComplete ? (

View File

@ -20,7 +20,7 @@ export default resolver.pipe(
const customerId = customer!.id; const customerId = customer!.id;
const phoneNumbers = await twilio( const phoneNumbers = await twilio(
customer!.accountSid!, customer!.accountSid!,
customer!.authToken! customer!.authToken!,
).incomingPhoneNumbers.list(); ).incomingPhoneNumbers.list();
const phoneNumber = phoneNumbers.find((phoneNumber) => phoneNumber.sid === phoneNumberSid)!; const phoneNumber = phoneNumbers.find((phoneNumber) => phoneNumber.sid === phoneNumberSid)!;
await db.phoneNumber.create({ await db.phoneNumber.create({
@ -36,5 +36,5 @@ export default resolver.pipe(
fetchCallsQueue.enqueue({ customerId }, { id: `fetch-messages-${customerId}` }), fetchCallsQueue.enqueue({ customerId }, { id: `fetch-messages-${customerId}` }),
setTwilioWebhooks.enqueue({ customerId }, { id: `set-twilio-webhooks-${customerId}` }), setTwilioWebhooks.enqueue({ customerId }, { id: `set-twilio-webhooks-${customerId}` }),
]); ]);
} },
); );

View File

@ -22,5 +22,5 @@ export default resolver.pipe(
authToken: twilioAuthToken, authToken: twilioAuthToken,
}, },
}); });
} },
); );

View File

@ -70,7 +70,7 @@ const StepThree: BlitzPage<Props> = ({ availablePhoneNumbers }) => {
className={clsx( className={clsx(
"max-w-[240px] mt-6 mx-auto w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 sm:text-sm", "max-w-[240px] mt-6 mx-auto w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 sm:text-sm",
!isSubmitting && "bg-primary-600 hover:bg-primary-700", !isSubmitting && "bg-primary-600 hover:bg-primary-700",
isSubmitting && "bg-primary-400 cursor-not-allowed" isSubmitting && "bg-primary-400 cursor-not-allowed",
)} )}
> >
Save Save
@ -131,7 +131,7 @@ export const getServerSideProps: GetServerSideProps<Props> = async ({ req, res }
const incomingPhoneNumbers = await twilio( const incomingPhoneNumbers = await twilio(
customer.accountSid, customer.accountSid,
customer.authToken customer.authToken,
).incomingPhoneNumbers.list(); ).incomingPhoneNumbers.list();
const phoneNumbers = incomingPhoneNumbers.map(({ phoneNumber, sid }) => ({ phoneNumber, sid })); const phoneNumbers = incomingPhoneNumbers.map(({ phoneNumber, sid }) => ({ phoneNumber, sid }));

View File

@ -1,7 +1,8 @@
import type { FunctionComponent } from "react";
import { Suspense, useEffect } from "react";
import type { BlitzPage, GetServerSideProps } from "blitz"; import type { BlitzPage, GetServerSideProps } from "blitz";
import { getSession, Routes, useMutation, useRouter } from "blitz"; import { getSession, Routes, useMutation, useRouter } from "blitz";
import clsx from "clsx"; import clsx from "clsx";
import { useEffect } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import db from "db"; import db from "db";
@ -80,7 +81,7 @@ const StepTwo: BlitzPage = () => {
className={clsx( className={clsx(
"max-w-[240px] mx-auto w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 sm:text-sm", "max-w-[240px] mx-auto w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 sm:text-sm",
!isSubmitting && "bg-primary-600 hover:bg-primary-700", !isSubmitting && "bg-primary-600 hover:bg-primary-700",
isSubmitting && "bg-primary-400 cursor-not-allowed" isSubmitting && "bg-primary-400 cursor-not-allowed",
)} )}
> >
Save Save
@ -90,7 +91,15 @@ const StepTwo: BlitzPage = () => {
); );
}; };
StepTwo.getLayout = function StepTwoLayout(page) { StepTwo.getLayout = (page) => {
return (
<Suspense fallback="Silence, ca pousse">
<StepTwoLayout>{page}</StepTwoLayout>
</Suspense>
);
};
const StepTwoLayout: FunctionComponent = ({ children }) => {
const { customer } = useCurrentCustomer(); const { customer } = useCurrentCustomer();
const initialAuthToken = customer?.authToken ?? ""; const initialAuthToken = customer?.authToken ?? "";
const initialAccountSid = customer?.accountSid ?? ""; const initialAccountSid = customer?.accountSid ?? "";
@ -106,7 +115,7 @@ StepTwo.getLayout = function StepTwoLayout(page) {
} }
previous={{ href: Routes.StepOne().pathname, label: "Back" }} previous={{ href: Routes.StepOne().pathname, label: "Back" }}
> >
{page} {children}
</OnboardingLayout> </OnboardingLayout>
); );
}; };

View File

@ -21,7 +21,7 @@ const fetchCallsQueue = Queue<Payload>("api/queue/fetch-calls", async ({ custome
}), }),
]); ]);
const calls = [...callsSent, ...callsReceived].sort( const calls = [...callsSent, ...callsReceived].sort(
(a, b) => a.dateCreated.getTime() - b.dateCreated.getTime() (a, b) => a.dateCreated.getTime() - b.dateCreated.getTime(),
); );
await insertCallsQueue.enqueue( await insertCallsQueue.enqueue(
@ -31,7 +31,7 @@ const fetchCallsQueue = Queue<Payload>("api/queue/fetch-calls", async ({ custome
}, },
{ {
id: `insert-calls-${customerId}`, id: `insert-calls-${customerId}`,
} },
); );
}); });

View File

@ -28,5 +28,5 @@ export default resolver.pipe(
hasMore, hasMore,
count, count,
}; };
} },
); );

View File

@ -15,5 +15,5 @@ export default resolver.pipe(resolver.zod(GetCustomerPhoneNumber), async ({ cust
phoneNumber: true, phoneNumber: true,
phoneNumberSid: true, phoneNumberSid: true,
}, },
}) }),
); );

View File

@ -18,7 +18,7 @@ const Button: FunctionComponent<Props> = ({ children, type, variant, onClick, is
{ {
[VARIANTS_STYLES[variant].base]: !isDisabled, [VARIANTS_STYLES[variant].base]: !isDisabled,
[VARIANTS_STYLES[variant].disabled]: isDisabled, [VARIANTS_STYLES[variant].disabled]: isDisabled,
} },
)} )}
disabled={isDisabled} disabled={isDisabled}
> >

View File

@ -72,7 +72,7 @@ export default function DangerZone() {
{ {
"bg-red-400 cursor-not-allowed": isDeletingUser, "bg-red-400 cursor-not-allowed": isDeletingUser,
"bg-red-600 hover:bg-red-700": !isDeletingUser, "bg-red-600 hover:bg-red-700": !isDeletingUser,
} },
)} )}
onClick={onConfirm} onClick={onConfirm}
disabled={isDeletingUser} disabled={isDeletingUser}
@ -87,7 +87,7 @@ export default function DangerZone() {
{ {
"bg-gray-50 cursor-not-allowed": isDeletingUser, "bg-gray-50 cursor-not-allowed": isDeletingUser,
"hover:bg-gray-50": !isDeletingUser, "hover:bg-gray-50": !isDeletingUser,
} },
)} )}
onClick={closeModal} onClick={closeModal}
disabled={isDeletingUser} disabled={isDeletingUser}

View File

@ -36,7 +36,7 @@ export function forgotPasswordMailer({ to, token }: ResetPasswordMailer) {
// TODO - send the production email, like this: // TODO - send the production email, like this:
// await postmark.sendEmail(msg) // await postmark.sendEmail(msg)
throw new Error( throw new Error(
"No production email implementation in mailers/forgotPasswordMailer" "No production email implementation in mailers/forgotPasswordMailer",
); );
} else { } else {
// Preview email in the browser // Preview email in the browser

View File

@ -21,7 +21,11 @@
"semi": true, "semi": true,
"useTabs": true, "useTabs": true,
"tabWidth": 4, "tabWidth": 4,
"printWidth": 100 "printWidth": 100,
"trailingComma": "all",
"jsxBracketSameLine": false,
"quoteProps": "as-needed",
"singleQuote": false
}, },
"lint-staged": { "lint-staged": {
"*.{js,ts,tsx}": [ "*.{js,ts,tsx}": [

View File

@ -26,7 +26,7 @@ export * from "@testing-library/react";
// -------------------------------------------------- // --------------------------------------------------
export function render( export function render(
ui: RenderUI, ui: RenderUI,
{ wrapper, router, dehydratedState, ...options }: RenderOptions = {} { wrapper, router, dehydratedState, ...options }: RenderOptions = {},
) { ) {
if (!wrapper) { if (!wrapper) {
// Add a default context wrapper if one isn't supplied from the test // Add a default context wrapper if one isn't supplied from the test
@ -54,7 +54,7 @@ export function render(
// -------------------------------------------------- // --------------------------------------------------
export function renderHook( export function renderHook(
hook: RenderHook, hook: RenderHook,
{ wrapper, router, dehydratedState, ...options }: RenderHookOptions = {} { wrapper, router, dehydratedState, ...options }: RenderHookOptions = {},
) { ) {
if (!wrapper) { if (!wrapper) {
// Add a default context wrapper if one isn't supplied from the test // Add a default context wrapper if one isn't supplied from the test