import type { ActionFunction } from "@remix-run/node"; import { json } from "@remix-run/node"; import { getThemeSession } from "./session.server"; import { isTheme } from "./provider"; export const action: ActionFunction = async ({ request }) => { const themeSession = await getThemeSession(request); const requestText = await request.text(); const form = new URLSearchParams(requestText); const theme = form.get("theme"); if (!isTheme(theme)) { return json({ success: false, message: `theme value of ${theme ?? "null"} is not a valid theme`, }); } themeSession.setTheme(theme); return json( { success: true }, { headers: { "Set-Cookie": await themeSession.commit() } } ); };