Skip to content

feat(plugin-multi-tenant): prompt the user to accept changing tenants before actually changing #12382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 14, 2025

Conversation

JarrodMFlesch
Copy link
Contributor

@JarrodMFlesch JarrodMFlesch commented May 12, 2025

Before you could easily change the tenant on any given doc by using the globally available multi-select. This would change the tenant without the user truly knowing what they were doing. This change now forces the user confirm with a confirmation modal.

CleanShot.2025-05-14.at.09.38.13.mp4

@JarrodMFlesch JarrodMFlesch changed the title feat(plugin-multi-tenant): prompt the user to accept changing tenants before actually changing feat(plugin-multi-tenant): prompt the user to accept changing tenants before actually changing [skip lint] May 12, 2025
@JarrodMFlesch JarrodMFlesch changed the title feat(plugin-multi-tenant): prompt the user to accept changing tenants before actually changing [skip lint] feat(plugin-multi-tenant): prompt the user to accept changing tenants before actually changing [skip-lint] May 12, 2025
@JarrodMFlesch JarrodMFlesch changed the title feat(plugin-multi-tenant): prompt the user to accept changing tenants before actually changing [skip-lint] feat(plugin-multi-tenant): prompt the user to accept changing tenants before actually changing May 13, 2025
@JarrodMFlesch JarrodMFlesch marked this pull request as ready for review May 14, 2025 13:22
@JarrodMFlesch JarrodMFlesch merged commit faa7794 into main May 14, 2025
78 checks passed
@JarrodMFlesch JarrodMFlesch deleted the feat/multi-tenant-ask-before-change branch May 14, 2025 13:45
kendelljoseph pushed a commit that referenced this pull request May 15, 2025
Copy link
Contributor

🚀 This is included in version v3.38.0

@robclancy
Copy link
Contributor

We completely patched out this functionality to redirect to the index of the collection of the tenant changed to. Which is far more standard ux. Usually a data transfer is a danger option. It would be nice to have an option to do this.

@Lezzio
Copy link

Lezzio commented May 22, 2025

How did you patch this one @robclancy ? I agree this behaviour is more UX standard, it's the one we want too. Redirecting to the collections root or even admin root instead of transferring ownership.

Transferring ownership could be an option in the document settings rather than tied to the navigation action

@robclancy
Copy link
Contributor

robclancy commented May 23, 2025

I used the pnpm patch system. It isn't updated for this latest version though, it's on 3.37.

diff --git a/dist/components/TenantField/index.client.js b/dist/components/TenantField/index.client.js
index e0c16fa7044a43f134884eb6fa7022b5831b6b05..24e2c859cc4fa62ec12d0b760979299d7f4b6c3e 100644
--- a/dist/components/TenantField/index.client.js
+++ b/dist/components/TenantField/index.client.js
@@ -1,15 +1,24 @@
 'use client';
 import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
-import { RelationshipField, useField } from '@payloadcms/ui';
+import { RelationshipField, useField, useConfig } from '@payloadcms/ui';
+import { formatAdminURL } from '@payloadcms/ui/shared';
+import { useRouter } from 'next/navigation';
 import React from 'react';
 import { useTenantSelection } from '../../providers/TenantSelectionProvider/index.client.js';
 import './index.scss';
 const baseClass = 'tenantField';
 export const TenantField = (args)=>{
-    const { debug, unique } = args;
+    const { debug, unique, schemaPath } = args;
     const { setValue, value } = useField();
     const { options, selectedTenantID, setPreventRefreshOnChange, setTenant } = useTenantSelection();
     const hasSetValueRef = React.useRef(false);
+    const router = useRouter();
+    const { config } = useConfig()
+    const collectionSlug = schemaPath.split('.')[0]
+    const collectionPath = formatAdminURL({
+        adminRoute: config.routes.admin,
+        path: `/collections/${collectionSlug}`
+    })
     React.useEffect(()=>{
         if (!hasSetValueRef.current) {
             // set value on load
@@ -28,8 +37,12 @@ export const TenantField = (args)=>{
             }
             hasSetValueRef.current = true;
         } else if (!value || value !== selectedTenantID) {
-            // Update the field on the document value when the tenant is changed
-            setValue(selectedTenantID);
+            if (true && value && !unique) { // option here 
+                router.push(collectionPath)
+            } else {
+                // Update the field value when the tenant is changed
+                setValue(selectedTenantID);
+            }
         }
     }, [
         value,

The true in there is where I intended to put an option and make a PR but never got around to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants