Skip to content
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

Pass query string param of login type on nav button clicks to load login form on right setting #55

Closed
joelwass opened this issue Mar 5, 2019 · 12 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@joelwass
Copy link
Member

joelwass commented Mar 5, 2019

Currently, if I click "I'm a teacher" within the nav, the login form loads but with the default setting of "i'm a donor" selected in the toggle above the sign in form.

let's pass a query string param ?type=teacher with the navigation with "I'm a teacher" is selected, and then grab it off the query string param in the login page and pass it in as a prop to the loginForm component.

@joelwass joelwass added enhancement New feature or request help wanted Extra attention is needed labels Mar 5, 2019
@SahibArora
Copy link

Hi @joelwass, I can help on this one.
Thanks,

@SahibArora
Copy link

SahibArora commented Mar 6, 2019

Hi,
I was working on it but I am stuck here:

            <Link href='/signinregister' param={{type:'teacher'}}><a className='black ttu'>I'm a teacher</a></Link>```


How can I access the parameters in signinregister?

@joelwass
Copy link
Member Author

joelwass commented Mar 6, 2019

Use this https://github.com/zeit/next.js/blob/master/errors/url-deprecated.md

what that means is in the signinregister.js page you'll wrap the page export in withRouter.
then you'll access the router in the constructor of the signinregister.js:
const SignInSignUp = ({ router }) => (
then you'll pass in as a prop to the loginForm component:
type={router.query.type}

then you should access the type in the loginForm just with this.props.type and check if it's equal to 'teacher'

@stripedpajamas
Copy link
Member

stripedpajamas commented Mar 6, 2019

It might be better to use the built-in getInitialProps in the page component (https://github.com/zeit/next.js/tree/master#fetching-data-and-component-lifecycle).

It would look something like this:

const SignInSignUp = (props) => {
  // markup
  // props.teacher is true if teacher query was passed
}

SignInSignUp.getInitialProps = async ({ query }) => {
  console.log(query) // { type: 'teacher' }
  return { teacher: query.type === 'teacher' }
}

@joelwass
Copy link
Member Author

joelwass commented Mar 6, 2019

@SahibArora Definitely go with @stripedpajamas suggestion to avoid use of a HOC when not necessary

after adding the getInitialProps method that @stripedpajamas outlined, you can pass in the type prop to loginForm like i mentioned with type={props.teacher}

@SahibArora
Copy link

Thank you for your help @joelwass and @stripedpajamas. I will continue further on it.

@SahibArora
Copy link

SahibArora commented Mar 7, 2019

Hello again,
One good thing, I am very close.

Just one thing,
When I use the getInitialProps()

SignInSignUp.getInitialProps = async ({ query }) => { console.log(query.type) /* It gives me undefined */ return { teacher: query.type === 'teacher' } }

This is how I passed the parameters through Link -

<Link href={{pathname:'/signinregister', query:{type:'teacher'}}}><a className='black ttu'>I'm a teacher</a></Link>

Do you have any suggestions on this one, that why am I receiving the undefined.

@joelwass
Copy link
Member Author

joelwass commented Mar 7, 2019

I think you can just pass it into the Link component as follows:

<Link href='/signinregister?type=teacher' />

@stripedpajamas
Copy link
Member

@SahibArora Your getInitialProps func looks good. To pass in the query edit nav.js where it says

{ href: '/signinregister', label: 'I\'m a teacher' }
change it to
{ href: '/signinregister?type=teacher', label: 'I\'m a teacher' }

@joelwass
Copy link
Member Author

joelwass commented Mar 7, 2019

also if you could pass in type=donor for the donor links, that'd be great. Thanks @SahibArora !

@SahibArora
Copy link

I did the type=donor already. Will try your suggestion now.
Thank you, again for your help :)

@SahibArora
Copy link

It worked, perfect!
Thank you!
Will create the pull request now.

joelwass added a commit that referenced this issue Mar 8, 2019
Toggle button enhancement for [issue #55] done!
@joelwass joelwass closed this as completed Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants