Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: flow for deactivating and reactivating users
Brad Barbin3a274e2e102a
diff --git a/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTable.tsx b/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTable.tsxindex da7912bcac..ed8dd23434 100644--- a/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTable.tsx+++ b/apps/carbon/app/modules/users/ui/Customers/CustomerAccountsTable.tsx@@ -9,8 +9,7 @@ import {} from "@carbon/react";import type { ColumnDef } from "@tanstack/react-table";import { memo, useCallback, useMemo, useState } from "react";-import { BsEnvelope } from "react-icons/bs";-import { FaBan } from "react-icons/fa";+import { LuBan, LuMailCheck } from "react-icons/lu";import { Avatar, New, Table } from "~/components";import { Enumerable } from "~/components/Enumerable";import { usePermissions, useUrlParams } from "~/hooks";@@ -171,8 +170,8 @@ const CustomerAccountsTable = memo(}}disabled={!permissions.can("create", "users")}>- <BsEnvelope className="mr-2 h-4 w-4" />- <span>Send Account Invite</span>+ <LuMailCheck className="mr-2 h-4 w-4" />+ <span>Resend Account Invite</span></DropdownMenuItem><DropdownMenuItemonClick={() => {@@ -181,7 +180,7 @@ const CustomerAccountsTable = memo(}}disabled={!permissions.can("delete", "users")}>- <FaBan className="mr-2 h-4 w-4" />+ <LuBan className="mr-2 h-4 w-4" /><span>Deactivate Users</span></DropdownMenuItem></DropdownMenuContent>@@ -204,8 +203,8 @@ const CustomerAccountsTable = memo(resendInviteModal.onOpen();}}>- <MenuIcon icon={<BsEnvelope />} />- Send Account Invite+ <MenuIcon icon={<LuMailCheck />} />+ Resend Account Invite</MenuItem>{row.user?.active === true && (<MenuItem@@ -214,7 +213,7 @@ const CustomerAccountsTable = memo(deactivateCustomerModal.onOpen();}}>- <MenuIcon icon={<FaBan />} />+ <MenuIcon icon={<LuBan />} />Deactivate Customer</MenuItem>)}diff --git a/apps/carbon/app/modules/users/ui/Employees/EmployeesTable.tsx b/apps/carbon/app/modules/users/ui/Employees/EmployeesTable.tsxindex 6cf5db790b..6db02835ae 100644--- a/apps/carbon/app/modules/users/ui/Employees/EmployeesTable.tsx+++ b/apps/carbon/app/modules/users/ui/Employees/EmployeesTable.tsx@@ -10,9 +10,7 @@ import {import { useNavigate } from "@remix-run/react";import type { ColumnDef } from "@tanstack/react-table";import { memo, useCallback, useMemo, useState } from "react";-import { BsEnvelope } from "react-icons/bs";-import { FaBan } from "react-icons/fa";-import { LuPencil, LuShield } from "react-icons/lu";+import { LuBan, LuMailCheck, LuPencil, LuShield } from "react-icons/lu";import { EmployeeAvatar, Hyperlink, New, Table } from "~/components";import { Enumerable } from "~/components/Enumerable";import { usePermissions, useUrlParams } from "~/hooks";@@ -156,8 +154,8 @@ const EmployeesTable = memo(}}disabled={!permissions.can("create", "users")}>- <BsEnvelope className="mr-2 h-4 w-4" />- <span>Send Account Invite</span>+ <LuMailCheck className="mr-2 h-4 w-4" />+ <span>Resend Account Invite</span></DropdownMenuItem><DropdownMenuItemonClick={() => {@@ -166,7 +164,7 @@ const EmployeesTable = memo(}}disabled={!permissions.can("delete", "users")}>- <FaBan className="mr-2 h-4 w-4" />+ <LuBan className="mr-2 h-4 w-4" /><span>Deactivate Users</span></DropdownMenuItem></DropdownMenuContent>@@ -195,8 +193,8 @@ const EmployeesTable = memo(resendInviteModal.onOpen();}}>- <MenuIcon icon={<BsEnvelope />} />- Send Account Invite+ <MenuIcon icon={<LuMailCheck />} />+ Resend Account Invite</MenuItem>{row.active === true && (<MenuItem@@ -205,7 +203,7 @@ const EmployeesTable = memo(deactivateEmployeeModal.onOpen();}}>- <MenuIcon icon={<FaBan />} />+ <MenuIcon icon={<LuBan />} />Deactivate Account</MenuItem>)}diff --git a/apps/carbon/app/modules/users/ui/Suppliers/SupplierAccountsTable/SuppliersAccountsTable.tsx b/apps/carbon/app/modules/users/ui/Suppliers/SupplierAccountsTable/SuppliersAccountsTable.tsxindex ccf4e56db3..8bea968698 100644--- a/apps/carbon/app/modules/users/ui/Suppliers/SupplierAccountsTable/SuppliersAccountsTable.tsx+++ b/apps/carbon/app/modules/users/ui/Suppliers/SupplierAccountsTable/SuppliersAccountsTable.tsx@@ -9,8 +9,7 @@ import {} from "@carbon/react";import type { ColumnDef } from "@tanstack/react-table";import { memo, useCallback, useMemo, useState } from "react";-import { BsEnvelope } from "react-icons/bs";-import { FaBan } from "react-icons/fa";+import { LuBan, LuMailCheck } from "react-icons/lu";import { Avatar, New, Table } from "~/components";import { Enumerable } from "~/components/Enumerable";import { usePermissions, useUrlParams } from "~/hooks";@@ -166,8 +165,8 @@ const SupplierAccountsTable = memo(}}disabled={!permissions.can("create", "users")}>- <BsEnvelope className="mr-2 h-4 w-4" />- <span>Send Account Invite</span>+ <LuMailCheck className="mr-2 h-4 w-4" />+ <span>Resend Account Invite</span></DropdownMenuItem><DropdownMenuItemonClick={() => {@@ -176,7 +175,7 @@ const SupplierAccountsTable = memo(}}disabled={!permissions.can("delete", "users")}>- <FaBan className="mr-2 h-4 w-4" />+ <LuBan className="mr-2 h-4 w-4" /><span>Deactivate Users</span></DropdownMenuItem></DropdownMenuContent>@@ -199,8 +198,8 @@ const SupplierAccountsTable = memo(resendInviteModal.onOpen();}}>- <MenuIcon icon={<BsEnvelope />} />- Send Account Invite+ <MenuIcon icon={<LuMailCheck />} />+ Resend Account Invite</MenuItem>{row.user?.active === true && (<MenuItem@@ -209,7 +208,7 @@ const SupplierAccountsTable = memo(deactivateSupplierModal.onOpen();}}>- <MenuIcon icon={<FaBan />} />+ <MenuIcon icon={<LuBan />} />Deactivate Supplier</MenuItem>)}diff --git a/apps/carbon/app/modules/users/users.server.ts b/apps/carbon/app/modules/users/users.server.tsindex aefaacf45c..05394625a1 100644--- a/apps/carbon/app/modules/users/users.server.ts+++ b/apps/carbon/app/modules/users/users.server.ts@@ -394,6 +394,12 @@ export async function deactivateUser(.delete().eq("id", userId).eq("companyId", companyId),+ serviceRole+ .from("search")+ .delete()+ .eq("uuid", userId)+ .eq("companyId", companyId),+ serviceRole.from("employeeJob").delete().eq("id", userId),]);if (updatePermissions.error) {diff --git a/apps/carbon/app/routes/_public+/callback.tsx b/apps/carbon/app/routes/_public+/callback.tsxindex e99c6fdb6b..caafb6b85d 100644--- a/apps/carbon/app/routes/_public+/callback.tsx+++ b/apps/carbon/app/routes/_public+/callback.tsx@@ -13,13 +13,19 @@ import {} from "@carbon/auth/session.server";import { getUserByEmail } from "@carbon/auth/users.server";import { validator } from "@carbon/form";-import { useFetcher, useLocation } from "@remix-run/react";+import { Link, useFetcher, useLocation } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";import { useEffect, useRef, useState } from "react";import { refreshAccessToken } from "@carbon/auth/auth.server";-import { Alert, AlertDescription, AlertTitle } from "@carbon/react";+import {+ Alert,+ AlertDescription,+ AlertTitle,+ Button,+ VStack,+} from "@carbon/react";import { LuAlertTriangle } from "react-icons/lu";import type { FormActionData } from "~/types";import { path } from "~/utils/path";@@ -142,11 +148,26 @@ export default function AuthCallback() {/></div>{error ? (- <Alert className="mt-8" variant="destructive">- <LuAlertTriangle className="h-4 w-4" />- <AlertTitle>Error</AlertTitle>- <AlertDescription>{error}</AlertDescription>- </Alert>+ <div className="rounded-lg md:bg-card md:border md:border-border md:shadow-lg p-8 mt-8 w-[380px]">+ <VStack spacing={4}>+ <Alert variant="destructive">+ <LuAlertTriangle className="h-4 w-4" />+ <AlertTitle>Error</AlertTitle>+ <AlertDescription>{error}</AlertDescription>+ </Alert>+ {error.includes("expired") && (+ <>+ <p className="text-sm text-muted-foreground">+ But don't worry. You can use the forgot password flow to+ request a new magic link.+ </p>+ <Button size="lg" asChild className="w-full">+ <Link to={path.to.forgotPassword}>Forgot Password</Link>+ </Button>+ </>+ )}+ </VStack>+ </div>) : (<p className="text-muted-foreground">Loading...</p>)}diff --git a/apps/carbon/app/routes/_public+/forgot-password.tsx b/apps/carbon/app/routes/_public+/forgot-password.tsxindex ec849942f6..4bd7873473 100644--- a/apps/carbon/app/routes/_public+/forgot-password.tsx+++ b/apps/carbon/app/routes/_public+/forgot-password.tsx@@ -2,6 +2,8 @@ import {assertIsPost,error,forgotPasswordValidator,+ getCarbonServiceRole,+ getCompaniesForUser,success,} from "@carbon/auth";import { sendMagicLink } from "@carbon/auth/auth.server";@@ -56,12 +58,17 @@ export async function action({ request }: ActionFunctionArgs): FormActionData {const user = await getUserByEmail(email);if (user.data && user.data.active) {- const authSession = await sendMagicLink(email);-- if (!authSession) {- return json(error(authSession, "Failed to send magic link"), {- status: 500,- });+ const companies = await getCompaniesForUser(+ getCarbonServiceRole(),+ user.data.id+ );+ if (companies.length > 0) {+ const authSession = await sendMagicLink(email);+ if (!authSession) {+ return json(error(authSession, "Failed to send magic link"), {+ status: 500,+ });+ }}}@@ -88,7 +95,7 @@ export default function ForgotPasswordRoute() {{actionData?.success ? (<Alertvariant="success"- className="h-[240px] [&>svg]:left-8 [&>svg]:top-8 p-8"+ className="h-[240px] [&>svg]:left-8 [&>svg]:top-8 p-8 w-[380px]"><LuCheckCircle className="w-4 h-4" /><AlertTitle>Success</AlertTitle>diff --git a/apps/carbon/app/routes/_public+/login.tsx b/apps/carbon/app/routes/_public+/login.tsxindex 4f98685476..944721ca0f 100644--- a/apps/carbon/app/routes/_public+/login.tsx+++ b/apps/carbon/app/routes/_public+/login.tsx@@ -7,7 +7,13 @@ import {import { signInWithEmail, verifyAuthSession } from "@carbon/auth/auth.server";import { commitAuthSession, getAuthSession } from "@carbon/auth/session.server";import { ValidatedForm, validationError, validator } from "@carbon/form";-import { Alert, AlertTitle, Button, VStack } from "@carbon/react";+import {+ Alert,+ AlertDescription,+ AlertTitle,+ Button,+ VStack,+} from "@carbon/react";import { Link, useActionData, useSearchParams } from "@remix-run/react";import type {ActionFunctionArgs,@@ -99,7 +105,8 @@ export default function LoginRoute() {{result && result?.message && (<Alert variant="destructive"><LuAlertCircle className="w-4 h-4" />- <AlertTitle>{result?.message}</AlertTitle>+ <AlertTitle>Authentication Error</AlertTitle>+ <AlertDescription>{result?.message}</AlertDescription></Alert>)}diff --git a/apps/carbon/app/routes/_public+/reset-password.tsx b/apps/carbon/app/routes/_public+/reset-password.tsxindex 7c8c84677f..d550e41377 100644--- a/apps/carbon/app/routes/_public+/reset-password.tsx+++ b/apps/carbon/app/routes/_public+/reset-password.tsx@@ -33,6 +33,7 @@ export async function action({ request }: ActionFunctionArgs) {const { password } = validation.data;const { userId } = await requireAuthSession(request, { verify: true });+const updatePassword = await resetPassword(userId, password);if (updatePassword.error) {diff --git a/apps/developers/app/routes/_public+/login.tsx b/apps/developers/app/routes/_public+/login.tsxindex be3bf13935..2672742cb5 100644--- a/apps/developers/app/routes/_public+/login.tsx+++ b/apps/developers/app/routes/_public+/login.tsx@@ -16,7 +16,13 @@ import {validationError,validator,} from "@carbon/form";-import { Alert, AlertTitle, Button, VStack } from "@carbon/react";+import {+ Alert,+ AlertDescription,+ AlertTitle,+ Button,+ VStack,+} from "@carbon/react";import { Link, useActionData, useSearchParams } from "@remix-run/react";import type {ActionFunctionArgs,@@ -109,7 +115,8 @@ export default function LoginRoute() {{result && result?.message && (<Alert variant="destructive"><LuAlertCircle className="w-4 h-4" />- <AlertTitle>{result?.message}</AlertTitle>+ <AlertTitle>Authentication Error</AlertTitle>+ <AlertDescription>{result?.message}</AlertDescription></Alert>)}diff --git a/apps/mes/app/routes/_public+/login.tsx b/apps/mes/app/routes/_public+/login.tsxindex 867c7a51fb..6b079836df 100644--- a/apps/mes/app/routes/_public+/login.tsx+++ b/apps/mes/app/routes/_public+/login.tsx@@ -16,7 +16,13 @@ import {validationError,validator,} from "@carbon/form";-import { Alert, AlertTitle, Button, VStack } from "@carbon/react";+import {+ Alert,+ AlertDescription,+ AlertTitle,+ Button,+ VStack,+} from "@carbon/react";import { Link, useActionData, useSearchParams } from "@remix-run/react";import type {ActionFunctionArgs,@@ -106,7 +112,8 @@ export default function LoginRoute() {{result && result?.message && (<Alert variant="destructive"><LuAlertCircle className="w-4 h-4" />- <AlertTitle>{result?.message}</AlertTitle>+ <AlertTitle>Authentication Error</AlertTitle>+ <AlertDescription>{result?.message}</AlertDescription></Alert>)}