I would like to add a component to the account page in the dashboard. i can fully replace it but i would like to only add something similar to beforeDashboard etc.
is there a way to import the payload AccountView into my custom AccountView?
Hey
@277050857852370944,
Unfortunately I don't believe the
Accountview supports something like a
beforeDashboardand I don't think you can import that view as it's not listed as an export from what I can tell
One thing you could consider, is taking a look at how Payload ships the view by default, and extending it in your own codebase
i will take a look at that. thanks for the quick help !
another thought i had was to define a UI Field that would add what i need into the view , however i dont really want the component to be viewed when viewing other users in the collection. i might be able to check for the path and not load the UI component then but then feels a bit hacky
Sorry, is this for your
Usercollection document views? Or is it for the
Accountview located at /account?
its meant for the "/admin/account" view
in my case the account there is a user of the user collection though
Aha, I see what you're saying. Yeah, actually your idea of the UI field could work! One thing you could do is to simply return
nullif you can find a way to reduce that particular user to a predicate so that the UI field doesn't show for the others
yeah , i will try the UI component really quick, that seems like something i can test fast and if i got trouble with that i will look into how payload renders the view. thanks again for the help, i would report back once i tested the UI component and consider this post resolved then
Excellent, yeah give it a shot! It's my pleasure
import { useLocation } from 'react-router-dom';
const CustomAccountView: React.FC<UIField> = (props) => {
const location = useLocation(); // Get the current location object
const currentUrl = location.pathname; // Access the current URL path
if(currentUrl !== '/admin/account'){
return (null);
}
else{
...
}
}this custom UI field i added into my user collection solved the issue. its under the Email field, so not exactly "before" the other fields but good enough for what i needed.
thanks again 🙂
Hey @Nog, are your
useLocation()still working as expected? It throws in my custom components everywhere. Please let me know if you've had issues with it since you posted this ✌️
Update, turns out Payload migrated off React Router onto Next.js, and if you want pathname there's a Next hook
usePathnameStar
Discord
online
Get dedicated engineering support directly from the Payload team.