708ebbde14
* Don’t show the Ready To Run Job prompt if you have an Integration that needs attention * Don’t highlight the row red or green * Improvements to the contrast of the app sections and dividers * Removed the Jobs page title as it’s duped info * using the new border variable * Sticky last table cell * Improved the sticky last table cell * Make any last cell in a table sticky by adding isSticky to it * Added a dropdown menu to the menu table cell * table rows can be marked as disabled by adding disabled * Using the jobTestPath function for the test path * tidy up imports * Removed un-used props * Removed the green badge variant * Added a new status badge to the Runs table * Clicking the gradient clicks the row * Delete Job triggers a modal popup * Added a large danger button type * Added some modal styling and started adding data * Added more styling and data to the delete job modal * A table can now be given a full width prop * Large danger button added to Storybook * Danger button disabled state looks disabled now * New active badge component to display in the table and logic for showing the env data * Style updates to the dialog component * active and job status badges can now have a small size * Added a new named icon * The Job page shows the Job status in the PageInfoRow * Small badge style update * Runs table has a sticky right cell * Created a JobStatusTable component * Added some placeholder help panel content for disabling a Job * WIP creating a Settings page * Added a delete button that triggers the delete modal – just need data hooking up * Implemented deleting jobs from the dashboard --------- Co-authored-by: Eric Allam <eallam@icloud.com>
179 lines
4.0 KiB
TypeScript
179 lines
4.0 KiB
TypeScript
import { json, Session } from "@remix-run/node";
|
|
import { redirect } from "remix-typedjson";
|
|
import { createCookieSessionStorage } from "@remix-run/node";
|
|
import { env } from "~/env.server";
|
|
|
|
export type ToastMessage = {
|
|
message: string;
|
|
type: "success" | "error";
|
|
options: Required<ToastMessageOptions>;
|
|
};
|
|
|
|
export type ToastMessageOptions = {
|
|
/** Ephemeral means it disappears after a delay, defaults to true */
|
|
ephemeral?: boolean;
|
|
};
|
|
|
|
const ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
|
|
|
|
export const { commitSession, getSession } = createCookieSessionStorage({
|
|
cookie: {
|
|
name: "__message",
|
|
path: "/",
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
secrets: [env.SESSION_SECRET],
|
|
secure: env.NODE_ENV === "production",
|
|
},
|
|
});
|
|
|
|
export function setSuccessMessage(
|
|
session: Session,
|
|
message: string,
|
|
options?: ToastMessageOptions
|
|
) {
|
|
session.flash("toastMessage", {
|
|
message,
|
|
type: "success",
|
|
options: {
|
|
ephemeral: options?.ephemeral ?? true,
|
|
},
|
|
} as ToastMessage);
|
|
}
|
|
|
|
export function setErrorMessage(session: Session, message: string, options?: ToastMessageOptions) {
|
|
session.flash("toastMessage", {
|
|
message,
|
|
type: "error",
|
|
options: {
|
|
ephemeral: options?.ephemeral ?? true,
|
|
},
|
|
} as ToastMessage);
|
|
}
|
|
|
|
export async function setRequestErrorMessage(
|
|
request: Request,
|
|
message: string,
|
|
options?: ToastMessageOptions
|
|
) {
|
|
const session = await getSession(request.headers.get("cookie"));
|
|
|
|
setErrorMessage(session, message, options);
|
|
|
|
return session;
|
|
}
|
|
|
|
export async function setRequestSuccessMessage(
|
|
request: Request,
|
|
message: string,
|
|
options?: ToastMessageOptions
|
|
) {
|
|
const session = await getSession(request.headers.get("cookie"));
|
|
|
|
setSuccessMessage(session, message, options);
|
|
|
|
return session;
|
|
}
|
|
|
|
export async function setToastMessageCookie(session: Session) {
|
|
return {
|
|
"Set-Cookie": await commitSession(session, {
|
|
expires: new Date(Date.now() + ONE_YEAR),
|
|
}),
|
|
};
|
|
}
|
|
|
|
export async function jsonWithSuccessMessage(
|
|
data: any,
|
|
request: Request,
|
|
message: string,
|
|
options?: ToastMessageOptions
|
|
) {
|
|
const session = await getSession(request.headers.get("cookie"));
|
|
|
|
setSuccessMessage(session, message, options);
|
|
|
|
return json(data, {
|
|
headers: {
|
|
"Set-Cookie": await commitSession(session, {
|
|
expires: new Date(Date.now() + ONE_YEAR),
|
|
}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function jsonWithErrorMessage(
|
|
data: any,
|
|
request: Request,
|
|
message: string,
|
|
options?: ToastMessageOptions
|
|
) {
|
|
const session = await getSession(request.headers.get("cookie"));
|
|
|
|
setErrorMessage(session, message, options);
|
|
|
|
return json(data, {
|
|
headers: {
|
|
"Set-Cookie": await commitSession(session, {
|
|
expires: new Date(Date.now() + ONE_YEAR),
|
|
}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function redirectWithSuccessMessage(
|
|
path: string,
|
|
request: Request,
|
|
message: string,
|
|
options?: ToastMessageOptions
|
|
) {
|
|
const session = await getSession(request.headers.get("cookie"));
|
|
|
|
setSuccessMessage(session, message, options);
|
|
|
|
return redirect(path, {
|
|
headers: {
|
|
"Set-Cookie": await commitSession(session, {
|
|
expires: new Date(Date.now() + ONE_YEAR),
|
|
}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function redirectWithErrorMessage(
|
|
path: string,
|
|
request: Request,
|
|
message: string,
|
|
options?: ToastMessageOptions
|
|
) {
|
|
const session = await getSession(request.headers.get("cookie"));
|
|
|
|
setErrorMessage(session, message, options);
|
|
|
|
return redirect(path, {
|
|
headers: {
|
|
"Set-Cookie": await commitSession(session, {
|
|
expires: new Date(Date.now() + ONE_YEAR),
|
|
}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function redirectBackWithErrorMessage(
|
|
request: Request,
|
|
message: string,
|
|
options?: ToastMessageOptions
|
|
) {
|
|
const url = new URL(request.url);
|
|
return redirectWithErrorMessage(url.pathname, request, message, options);
|
|
}
|
|
|
|
export async function redirectBackWithSuccessMessage(
|
|
request: Request,
|
|
message: string,
|
|
options?: ToastMessageOptions
|
|
) {
|
|
const url = new URL(request.url);
|
|
return redirectWithSuccessMessage(url.pathname, request, message, options);
|
|
}
|