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

fix: add redirection logic for works page #7614

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/v2/Apps/Partner/partnerRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,38 @@ export const partnerRoutes: AppRouteConfig[] = [
) {
partner(id: $partnerId) @principalField {
...Works_partner @arguments(input: $input)
displayWorksSection
counts {
eligibleArtworks
}
}
}
`,
render: ({ Component, props, match }) => {
if (!(Component && props)) {
return
}

const { partner } = props as any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to get rid of this any?

Looks like you could also shorten this to if (!props.partner) ... which might avoid this as well.

Copy link
Contributor Author

@ivan-badyulya ivan-badyulya May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2021-05-24 at 4 33 44 PM

This way wouldn't avoid the problem. The TS defines props as field from found lib and can't find the partner field in render props type, that's why we decided avoiding the issue with as any

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@damassi do you know if there's a way to provide types for the render function?


if (!partner) {
return
}

const {
displayWorksSection,
counts: { eligibleArtworks },
} = partner

if (!displayWorksSection || eligibleArtworks <= 0) {
throw new RedirectException(
`/partner2/${match.params.partnerId}`,
302
)
}

return <Component {...props} />
},
},
{
getComponent: () => ArtistsRoute,
Expand Down
117 changes: 77 additions & 40 deletions src/v2/__generated__/partnerRoutes_WorksQuery.graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.