diff --git a/app/features/calendar/routes/calendar.new.tsx b/app/features/calendar/routes/calendar.new.tsx index 6d1b0c0d0..e15c49e3d 100644 --- a/app/features/calendar/routes/calendar.new.tsx +++ b/app/features/calendar/routes/calendar.new.tsx @@ -53,7 +53,7 @@ import { validate, type SendouRouteHandle, } from "~/utils/remix"; -import { makeTitle } from "~/utils/strings"; +import { makeTitle, pathnameFromPotentialURL } from "~/utils/strings"; import { calendarEventPage } from "~/utils/urls"; import { actualNumber, @@ -471,6 +471,9 @@ function BracketUrlInput() { function DiscordLinkInput() { const { t } = useTranslation("calendar"); const { eventToEdit } = useLoaderData(); + const [value, setValue] = React.useState( + eventToEdit?.discordInviteCode ?? "", + ); return (
@@ -479,7 +482,8 @@ function DiscordLinkInput() { name="discordInviteCode" leftAddon="https://discord.gg/" maxLength={CALENDAR_EVENT.DISCORD_INVITE_CODE_MAX_LENGTH} - defaultValue={eventToEdit?.discordInviteCode ?? undefined} + value={value} + onChange={(e) => setValue(pathnameFromPotentialURL(e.target.value))} />
); diff --git a/app/features/plus-voting/core/voting-time.test.ts b/app/features/plus-voting/core/voting-time.test.ts deleted file mode 100644 index ad293d13c..000000000 --- a/app/features/plus-voting/core/voting-time.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { suite } from "uvu"; -import * as assert from "uvu/assert"; -import { lastCompletedVoting } from "./voting-time"; - -const LastCompletedVoting = suite("lastCompletedVoting()"); - -LastCompletedVoting("Previous month if voting yet to happen", () => { - assert.equal(lastCompletedVoting(new Date(Date.UTC(2022, 4, 1))), { - month: 3, - year: 2022, - }); -}); - -LastCompletedVoting("Previous month if voting in progress", () => { - assert.equal(lastCompletedVoting(new Date(Date.UTC(2022, 4, 7))), { - month: 3, - year: 2022, - }); -}); - -LastCompletedVoting("Same month if voting over", () => { - assert.equal(lastCompletedVoting(new Date(Date.UTC(2022, 4, 15))), { - month: 4, - year: 2022, - }); -}); - -LastCompletedVoting.run(); diff --git a/app/features/team/routes/t.$customUrl.edit.tsx b/app/features/team/routes/t.$customUrl.edit.tsx index 7436092a6..377efcfb8 100644 --- a/app/features/team/routes/t.$customUrl.edit.tsx +++ b/app/features/team/routes/t.$customUrl.edit.tsx @@ -24,7 +24,7 @@ import { validate, type SendouRouteHandle, } from "~/utils/remix"; -import { makeTitle } from "~/utils/strings"; +import { makeTitle, pathnameFromPotentialURL } from "~/utils/strings"; import { assertUnreachable } from "~/utils/types"; import { mySlugify, @@ -40,6 +40,7 @@ import { TEAM } from "../team-constants"; import { editTeamSchema, teamParamsSchema } from "../team-schemas.server"; import { canAddCustomizedColors, isTeamOwner } from "../team-utils"; import styles from "../team.css"; +import { Input } from "~/components/Input"; export const links: LinksFunction = () => { return [{ rel: "stylesheet", href: styles }]; @@ -220,15 +221,18 @@ function NameInput() { function TwitterInput() { const { t } = useTranslation(["team"]); const { team } = useLoaderData(); + const [value, setValue] = React.useState(team.twitter ?? ""); return (
- setValue(pathnameFromPotentialURL(e.target.value))} data-testid="twitter-input" />
diff --git a/app/utils/string.test.ts b/app/utils/string.test.ts new file mode 100644 index 000000000..4784ea84f --- /dev/null +++ b/app/utils/string.test.ts @@ -0,0 +1,15 @@ +import { suite } from "uvu"; +import * as assert from "uvu/assert"; +import { pathnameFromPotentialURL } from "./strings"; + +const PathnameFromPotentialURL = suite("pathnameFromPotentialURL()"); + +PathnameFromPotentialURL("Resolves path name from valid URL", () => { + assert.is(pathnameFromPotentialURL("https://twitter.com/sendouc"), "sendouc"); +}); + +PathnameFromPotentialURL("Returns string as is if not URL", () => { + assert.is(pathnameFromPotentialURL("sendouc"), "sendouc"); +}); + +PathnameFromPotentialURL.run(); diff --git a/app/utils/strings.ts b/app/utils/strings.ts index e5bae1dd2..6b4fd9a85 100644 --- a/app/utils/strings.ts +++ b/app/utils/strings.ts @@ -72,3 +72,11 @@ export function gearTypeToInitial(gearType: GearType) { export function capitalize(str: string) { return str[0].toUpperCase() + str.slice(1); } + +export function pathnameFromPotentialURL(maybeUrl: string) { + try { + return new URL(maybeUrl).pathname.replace("/", ""); + } catch { + return maybeUrl; + } +}