Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mplewis committed Oct 24, 2024
1 parent 0a0f8db commit 4f88f50
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 90 deletions.
27 changes: 16 additions & 11 deletions api/src/lib/email/template.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { stripIndent } from "common-tags"
import { stripIndent } from 'common-tags'
import { Event, Response } from 'types/graphql'

import { SITE_HOST } from "src/app.config"
import { SITE_HOST } from 'src/app.config'

import { sendEmail } from "./send"
import { Event, Response } from "types/graphql"
import { sendEmail } from './send'

/**
* Email the admin link for a newly-created event to its owner.
* @param event The newly-created event
* @returns The result of the send operation
*/
export async function sendEventDetails(
event: Pick<Event, "ownerEmail" | "title" | "editToken">
event: Pick<Event, 'ownerEmail' | 'title' | 'editToken'>
) {
return sendEmail({
to: event.ownerEmail,
Expand Down Expand Up @@ -41,8 +41,8 @@ export async function sendResponseConfirmation({
event,
response,
}: {
event: Pick<Event, "title">;
response: Pick<Response, "email" | "editToken">;
event: Pick<Event, 'title'>
response: Pick<Response, 'email' | 'editToken'>
}) {
return sendEmail({
to: response.email,
Expand All @@ -68,13 +68,18 @@ export async function sendResponseConfirmation({
* @param response The response that was received
* @returns The result of the send operation
*/
export async function sendNewResponseReceived({ event, response }: {
event: Pick<Event, "title" | "ownerEmail" | "editToken">;
response: Pick<Response, "name" | "headCount" | "comment">;
export async function sendNewResponseReceived({
event,
response,
}: {
event: Pick<Event, 'title' | 'ownerEmail' | 'editToken'>
response: Pick<Response, 'name' | 'headCount' | 'comment'>
}) {
return sendEmail({
to: event.ownerEmail,
subject: `New RSVP: ${response.name} (${response.headCount}) ${response.headCount === 1 ? 'is' : 'are'} attending ${event.title}`,
subject:
`New RSVP: ${response.name} (${response.headCount}) ` +
`${response.headCount === 1 ? 'is' : 'are'} attending ${event.title}`,
text: stripIndent`
Hello from Freevite! ${response.name} has confirmed they are attending ${event.title}:
Expand Down
86 changes: 44 additions & 42 deletions api/src/services/events/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Event } from "@prisma/client";
import type { Event } from '@prisma/client'

import {
eventBySlug,
Expand All @@ -7,17 +7,19 @@ import {
createEvent,
updateEvent,
deleteEvent,
} from "./events";
import type { StandardScenario } from "./events.scenarios";
} from './events'
import type { StandardScenario } from './events.scenarios'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function noMutables(event: any) {
const { createdAt, updatedAt, id, ...rest } = event;
return rest;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { createdAt, updatedAt, id, ...rest } = event
return rest
}

describe("events", () => {
scenario("returns an event by slug", async (scenario: StandardScenario) => {
const result = await eventBySlug({ slug: scenario.event.visible.slug });
describe('events', () => {
scenario('returns an event by slug', async (scenario: StandardScenario) => {
const result = await eventBySlug({ slug: scenario.event.visible.slug })
expect(noMutables(result)).toMatchInlineSnapshot(`
{
"description": "String",
Expand All @@ -30,23 +32,23 @@ describe("events", () => {
"timezone": null,
"title": "String",
}
`);
});
`)
})

scenario(
"does not return an invisible event by slug",
'does not return an invisible event by slug',
async (scenario: StandardScenario) => {
const result = await eventBySlug({ slug: scenario.event.invisible.slug });
expect(result).toBeNull();
const result = await eventBySlug({ slug: scenario.event.invisible.slug })
expect(result).toBeNull()
}
);
)

scenario(
"returns an event by editToken",
'returns an event by editToken',
async (scenario: StandardScenario) => {
const result = await eventByEditToken({
editToken: scenario.event.visible.editToken,
});
})
expect(noMutables(result)).toMatchInlineSnapshot(`
{
"confirmed": true,
Expand All @@ -62,16 +64,16 @@ describe("events", () => {
"title": "String",
"visible": true,
}
`);
`)
}
);
)

scenario(
"returns an event by previewToken",
'returns an event by previewToken',
async (scenario: StandardScenario) => {
const result = await eventByPreviewToken({
previewToken: scenario.event.visible.previewToken,
});
})
expect(noMutables(result)).toMatchInlineSnapshot(`
{
"confirmed": true,
Expand All @@ -87,38 +89,38 @@ describe("events", () => {
"title": "String",
"visible": true,
}
`);
`)
}
);
)

scenario("creates a event", async () => {
scenario('creates a event', async () => {
const result = await createEvent({
input: {
ownerEmail: "[email protected]",
title: "My birthday party",
responseConfig: "DISABLED",
ownerEmail: '[email protected]',
title: 'My birthday party',
responseConfig: 'DISABLED',
},
});
expect(result.ownerEmail).toEqual("[email protected]");
expect(result.title).toEqual("My birthday party");
});
})
expect(result.ownerEmail).toEqual('[email protected]')
expect(result.title).toEqual('My birthday party')
})

scenario("updates a event", async (scenario: StandardScenario) => {
scenario('updates a event', async (scenario: StandardScenario) => {
const original = (await eventByEditToken({
editToken: scenario.event.visible.editToken,
})) as Event;
})) as Event
const result = await updateEvent({
editToken: original.editToken,
input: { title: "My going-away party" },
});
expect(result.title).toEqual("My going-away party");
});
input: { title: 'My going-away party' },
})
expect(result.title).toEqual('My going-away party')
})

scenario("deletes a event", async (scenario: StandardScenario) => {
scenario('deletes a event', async (scenario: StandardScenario) => {
const original = (await deleteEvent({
editToken: scenario.event.visible.editToken,
})) as Event;
const result = await eventByEditToken({ editToken: original.editToken });
expect(result).toBeNull();
});
});
})) as Event
const result = await eventByEditToken({ editToken: original.editToken })
expect(result).toBeNull()
})
})
5 changes: 4 additions & 1 deletion api/src/services/responses/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import type {
} from 'types/graphql'

import { db } from 'src/lib/db'
import { sendNewResponseReceived, sendResponseConfirmation } from 'src/lib/email/template'
import {
sendNewResponseReceived,
sendResponseConfirmation,
} from 'src/lib/email/template'
import { generateToken } from 'src/lib/token'

export const responses: QueryResolvers['responses'] = () => {
Expand Down
75 changes: 39 additions & 36 deletions web/src/pages/NewEventPage/NewEventPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useState } from "react";
import { useState } from 'react'

import {
CreateEventMutation,
CreateEventMutationVariables,
ResponseConfig,
} from "types/graphql";
} from 'types/graphql'

import {
Form,
Expand All @@ -14,20 +14,20 @@ import {
Submit,
useForm,
SelectField,
} from "@redwoodjs/forms";
import { navigate, routes } from "@redwoodjs/router";
import { useMutation } from "@redwoodjs/web";
} from '@redwoodjs/forms'
import { navigate, routes } from '@redwoodjs/router'
import { useMutation } from '@redwoodjs/web'

import FormField from "src/components/FormField/FormField";
import PageHead from "src/components/PageHead/PageHead";
import Typ from "src/components/Typ/Typ";
import { isEmail } from "src/logic/validation";
import { fieldAttrs, formErrorAttrs } from "src/styles/classes";
import FormField from 'src/components/FormField/FormField'
import PageHead from 'src/components/PageHead/PageHead'
import Typ from 'src/components/Typ/Typ'
import { isEmail } from 'src/logic/validation'
import { fieldAttrs, formErrorAttrs } from 'src/styles/classes'

interface FormValues {
ownerEmail: string;
title: string;
responseConfig: ResponseConfig;
ownerEmail: string
title: string
responseConfig: ResponseConfig
}

const CREATE_EVENT = gql`
Expand All @@ -38,43 +38,46 @@ const CREATE_EVENT = gql`
responseConfig
}
}
`;
`

const responseConfigOptions: { config: ResponseConfig; label: string }[] = [
{
config: "SHOW_ALL",
label: "Accept responses and display them to other attendees (name, head count, comments)",
config: 'SHOW_ALL',
label:
'Accept responses and display them to other attendees (name, head count, comments)',
},
{
config: "SHOW_COUNTS_ONLY",
label: "Accept responses and display only head counts to other attendees (hide name and comments)",
config: 'SHOW_COUNTS_ONLY',
label:
'Accept responses and display only head counts to other attendees (hide name and comments)',
},
{
config: "SHOW_NONE",
label: "Accept responses and hide details from other attendees (only you can see them)",
config: 'SHOW_NONE',
label:
'Accept responses and hide details from other attendees (only you can see them)',
},
{ config: "DISABLED", label: "Do not accept responses" },
];
{ config: 'DISABLED', label: 'Do not accept responses' },
]

const NewEventPage = () => {
const formMethods = useForm({
mode: "onTouched",
defaultValues: { ownerEmail: "", title: "" },
});
const { formState } = formMethods;
mode: 'onTouched',
defaultValues: { ownerEmail: '', title: '' },
})
const { formState } = formMethods

const [redirecting, setRedirecting] = useState(false);
const [redirecting, setRedirecting] = useState(false)

const [create, { loading, error }] = useMutation<
CreateEventMutation,
CreateEventMutationVariables
>(CREATE_EVENT, {
onCompleted: (data) => {
const { ownerEmail, title } = data.createEvent;
setRedirecting(true);
navigate(routes.eventCreated({ email: ownerEmail, title }));
const { ownerEmail, title } = data.createEvent
setRedirecting(true)
navigate(routes.eventCreated({ email: ownerEmail, title }))
},
});
})

return (
<>
Expand Down Expand Up @@ -114,7 +117,7 @@ const NewEventPage = () => {
<FormField name="responseConfig" text="Accept responses?*">
<Typ x="labelDetails">
Freevite can send you an email when guests RSVP to your event. This
can't be changed later.
can&apos;t be changed later.
</Typ>
<SelectField
name="responseConfig"
Expand All @@ -134,12 +137,12 @@ const NewEventPage = () => {
className="button is-success mt-3"
disabled={loading || redirecting || !formState.isValid}
>
{loading || redirecting ? "Creating..." : "Create New Event"}
{loading || redirecting ? 'Creating...' : 'Create New Event'}
</Submit>
<FormError error={error} {...formErrorAttrs} />
</Form>
</>
);
};
)
}

export default NewEventPage;
export default NewEventPage

0 comments on commit 4f88f50

Please sign in to comment.