Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Custom Accountview

default discord avatar
shiru_noglast year
9

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?

  • default discord avatar
    zed0547last year

    Hey

    @277050857852370944

    ,



    Unfortunately I don't believe the

    Account

    view supports something like a

    beforeDashboard

    and 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



    https://github.com/payloadcms/payload/tree/beta/packages/next/src/views/Account
  • default discord avatar
    shiru_noglast year

    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

  • default discord avatar
    zed0547last year

    Sorry, is this for your

    User

    collection document views? Or is it for the

    Account

    view located at /account?

  • default discord avatar
    shiru_noglast year

    its meant for the "/admin/account" view



    in my case the account there is a user of the user collection though

  • default discord avatar
    zed0547last year

    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

    null

    if you can find a way to reduce that particular user to a predicate so that the UI field doesn't show for the others

  • default discord avatar
    shiru_noglast year

    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

  • default discord avatar
    zed0547last year

    Excellent, yeah give it a shot! It's my pleasure

  • default discord avatar
    shiru_noglast year
    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 🙂

  • default discord avatar
    ingrid74111 months ago

    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

    usePathname
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.