Skip to content

Commit ea98b35

Browse files
authored
fix: APP-850 various issues with org creation/profile (#2784)
1 parent fd8a54d commit ea98b35

File tree

9 files changed

+129
-51
lines changed

9 files changed

+129
-51
lines changed

web-components/src/components/cards/MemberCard/MemberCard.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export const MemberCard = ({
2121
editText,
2222
linkComponent: LinkComponent,
2323
}: Props) => (
24-
<article className="flex flex-col items-center relative px-20 py-40 border border-solid border-sc-card-standard-stroke rounded-[10px] shadow-[0_0_4px_0_rgba(0,0,0,0.05)]">
24+
<article
25+
aria-label={name}
26+
className="bg-grey-0 flex flex-col items-center relative px-20 py-40 border border-solid border-sc-card-standard-stroke rounded-[10px] shadow-[0_0_4px_0_rgba(0,0,0,0.05)]"
27+
>
2528
<UserAvatar src={imageSrc} alt={name} className="w-[120px] h-[120px]" />
2629
<Title className="py-10" variant="h6">
2730
{name}
Lines changed: 91 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use client';
22
import React, { forwardRef, PropsWithChildren } from 'react';
3+
import {
4+
Link as ReactRouterLink,
5+
LinkProps as ReactRouterLinkProps,
6+
} from 'react-router-dom';
37
import { Box, Link as MuiLink, LinkProps as MuiLinkProps } from '@mui/material';
48
import NextLink, { LinkProps as NextLinkProps } from 'next/link';
59

@@ -10,60 +14,105 @@ export interface LinkProps extends MuiLinkProps, PropsWithChildren {
1014
href: string;
1115
}
1216

13-
type LinkRef = HTMLAnchorElement;
14-
type CombinedLinkProps = Omit<
17+
type ReactRouterLinkBehaviorProps = Omit<ReactRouterLinkProps, 'to'> & {
18+
href: ReactRouterLinkProps['to'];
19+
};
20+
21+
type NextLinkBehaviorProps = Omit<
1522
React.AnchorHTMLAttributes<HTMLAnchorElement>,
1623
keyof NextLinkProps
1724
> &
1825
NextLinkProps;
1926

20-
const LinkBehavior = React.forwardRef<LinkRef, CombinedLinkProps>(
21-
(props, ref) => {
22-
const { href, as, ...other } = props;
23-
return <NextLink ref={ref} href={href} as={as} {...other} />;
24-
},
25-
);
27+
const ReactRouterLinkBehavior = React.forwardRef<
28+
HTMLAnchorElement,
29+
ReactRouterLinkBehaviorProps
30+
>(({ href, ...other }, ref) => {
31+
return <ReactRouterLink ref={ref} to={href} {...other} preventScrollReset />;
32+
});
33+
34+
const NextLinkBehavior = React.forwardRef<
35+
HTMLAnchorElement,
36+
NextLinkBehaviorProps
37+
>((props, ref) => {
38+
const { href, as, ...other } = props;
39+
return <NextLink ref={ref} href={href} as={as} {...other} />;
40+
});
2641

2742
// eslint-disable-next-line lingui/no-unlocalized-strings
28-
LinkBehavior.displayName = 'LinkBehavior';
43+
ReactRouterLinkBehavior.displayName = 'ReactRouterLinkBehavior';
44+
// eslint-disable-next-line lingui/no-unlocalized-strings
45+
NextLinkBehavior.displayName = 'NextLinkBehavior';
46+
const createMuiLink = (
47+
internalComponent: React.ElementType,
48+
{ applyLocalePrefix = true }: { applyLocalePrefix?: boolean } = {},
49+
) => {
50+
const Component = forwardRef<HTMLAnchorElement, LinkProps>(
51+
({ href, children, target, ...linkProps }, ref) => {
52+
const locale = useCurrentLocale();
53+
if (!href || typeof href !== 'string') {
54+
return (
55+
<Box {...linkProps} component="span">
56+
{children}
57+
</Box>
58+
);
59+
}
2960

30-
/**
31-
* Renders a Material UI `Link` - will use Next Link for local links.
32-
* Defaults to `target='_blank'` for external links.
33-
*/
34-
export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
35-
({ href, children, target, ...linkProps }, ref) => {
36-
const locale = useCurrentLocale();
37-
if (!href || typeof href !== 'string') {
38-
// @ts-expect-error
39-
return <Box {...linkProps}>{children}</Box>;
40-
}
61+
const isInternalLink = (href: string): boolean =>
62+
!!href && href.startsWith('/');
63+
64+
const internalHref =
65+
applyLocalePrefix && isInternalLink(href)
66+
? ensureLocalePrefix(href, locale)
67+
: href;
4168

42-
const isInternalLink = (href: string): boolean =>
43-
!!href && href.startsWith('/');
44-
// const hasAnchor = href?.includes('#');
69+
return isInternalLink(href) ? (
70+
<MuiLink
71+
{...linkProps}
72+
ref={ref}
73+
component={internalComponent}
74+
href={internalHref}
75+
>
76+
{children}
77+
</MuiLink>
78+
) : (
79+
<MuiLink
80+
{...linkProps}
81+
ref={ref}
82+
href={href}
83+
target={target || '_blank'}
84+
>
85+
{children}
86+
</MuiLink>
87+
);
88+
},
89+
);
4590

46-
const withLocalePrefix = (href: string): string =>
47-
isInternalLink(href) ? ensureLocalePrefix(href, locale) : href;
91+
const internalName =
92+
(internalComponent as React.ComponentType).displayName ||
93+
(internalComponent as React.ComponentType).name ||
94+
// eslint-disable-next-line lingui/no-unlocalized-strings
95+
'Component';
96+
// eslint-disable-next-line lingui/no-unlocalized-strings
97+
Component.displayName = `MuiLink(${internalName})`;
98+
return Component;
99+
};
48100

49-
const internalHref = withLocalePrefix(href);
101+
/**
102+
* Renders a Material UI `Link` - will use React Router Link for local links.
103+
* Defaults to `target='_blank'` for external links.
104+
*/
105+
export const ReactRouterMuiLink = createMuiLink(ReactRouterLinkBehavior, {
106+
applyLocalePrefix: false,
107+
});
50108

51-
return isInternalLink(href) ? (
52-
<MuiLink
53-
{...linkProps}
54-
ref={ref}
55-
component={LinkBehavior}
56-
href={internalHref}
57-
>
58-
{children}
59-
</MuiLink>
60-
) : (
61-
<MuiLink {...linkProps} ref={ref} href={href} target={target || '_blank'}>
62-
{children}
63-
</MuiLink>
64-
);
65-
},
66-
);
109+
/**
110+
* Renders a Material UI `Link` - will use Next Link for local links.
111+
* Defaults to `target='_blank'` for external links.
112+
*/
113+
export const Link = createMuiLink(NextLinkBehavior);
67114

115+
// eslint-disable-next-line lingui/no-unlocalized-strings
116+
ReactRouterMuiLink.displayName = 'ReactRouterMuiLink';
68117
// eslint-disable-next-line lingui/no-unlocalized-strings
69118
Link.displayName = 'Link';

web-marketplace/src/components/atoms/ScrollToTop.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useEffect } from 'react';
44
import { usePathname } from 'next/navigation';
55

66
// List of route segments that should not trigger a scroll reset
7-
const whitelist = ['ecocredit-batches'];
7+
const whitelist = ['ecocredit-batches', 'profiles'];
88

99
/**
1010
* Automatically scrolls the page to the top when navigating to a new route,
@@ -16,8 +16,9 @@ function ScrollToTop(): null {
1616
const pathname = usePathname();
1717

1818
useEffect(() => {
19-
if (!whitelist.some(route => pathname.includes(route)))
19+
if (!whitelist.some(route => pathname.includes(route))) {
2020
window.scrollTo(0, 0);
21+
}
2122
}, [pathname]);
2223

2324
return null; // No UI component, only side effect

web-marketplace/src/components/organisms/BridgedEcocreditsTable/hooks/useFetchBridgedEcocredits.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const useFetchBridgedEcocredits = ({ address }: Props): Output => {
7373
client: queryClient,
7474
enabled: !!queryClient,
7575
request: {
76+
// eslint-disable-next-line lingui/no-unlocalized-strings
7677
query: `${messageActionEquals}'${MsgBridge.typeUrl}' AND message.sender='${address}'`,
7778
orderBy: OrderBy.ORDER_BY_DESC,
7879
},
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
import { Outlet } from 'react-router-dom';
1+
import { Outlet, ScrollRestoration } from 'react-router-dom';
22

33
export const RegistryLayout = () => {
4-
return <Outlet />;
4+
return (
5+
<>
6+
<ScrollRestoration
7+
getKey={(location, matches) => {
8+
const profileMatch = matches.find(match =>
9+
match.pathname.startsWith('/profiles/'),
10+
);
11+
return profileMatch ? profileMatch.pathname : location.key;
12+
}}
13+
/>
14+
<Outlet />
15+
</>
16+
);
517
};

web-marketplace/src/features/ecocredit/BridgeFlow/BridgeFlow.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const BridgeFlow = ({
100100
reactQueryClient.invalidateQueries({
101101
queryKey: [
102102
GET_TXS_EVENT_KEY,
103+
// eslint-disable-next-line lingui/no-unlocalized-strings
103104
`${messageActionEquals}'${MsgBridge.typeUrl}' AND message.sender='${wallet?.address}'`,
104105
],
105106
});

web-marketplace/src/legacy-pages/CreateOrganization/hooks/useCreateDao/useCreateDao.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ export const useCreateDao = () => {
186186
key: 'organization_id',
187187
value: params.organizationId,
188188
});
189+
// this is required to move s3 media from the current account to the new org folder
190+
initialItems.push({
191+
key: 'creator_account_id',
192+
value: activeAccountId,
193+
});
189194
}
190195

191196
if (sanitizedBackgroundImage) {

web-marketplace/src/legacy-pages/Profile/MembersTab/MembersTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const MembersTab = () => {
2121
return (
2222
<WithLoader isLoading={isLoading}>
2323
{organization ? (
24-
<div className="grid grid-cols-1 sm:grid-cols-4 gap-4">
24+
<div className="grid grid-cols-1 sm:grid-cols-4 gap-20">
2525
{organization.daoByDaoAddress?.assignmentsByDaoAddress?.nodes.map(
2626
assignment => {
2727
const account = assignment?.accountByAccountId;

web-marketplace/src/legacy-pages/Profile/Profile.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
import { getProfileLink } from 'lib/profileLink';
3939
import { useWallet } from 'lib/wallet/wallet';
4040

41-
import { Link } from 'components/atoms';
41+
import { Link, ReactRouterMuiLink } from 'components/atoms';
4242
import WithLoader from 'components/atoms/WithLoader';
4343
import { useFetchPaginatedBatches } from 'hooks/batches/useFetchPaginatedBatches';
4444
import { useQueryIsIssuer } from 'hooks/useQueryIsIssuer';
@@ -226,6 +226,12 @@ export const Profile = (): JSX.Element => {
226226
socialsLinks,
227227
};
228228

229+
const editLink = isOwnProfile
230+
? organization
231+
? '/dashboard/organization/profile'
232+
: '/dashboard/profile'
233+
: '';
234+
229235
return (
230236
<WithLoader
231237
isLoading={isLoading || isLoadingIsIssuer}
@@ -250,7 +256,7 @@ export const Profile = (): JSX.Element => {
250256
backgroundImage={backgroundImage}
251257
avatar={avatarImage}
252258
infos={infos}
253-
editLink={isOwnProfile ? '/dashboard/profile' : ''}
259+
editLink={editLink}
254260
profileLink={profileLink}
255261
variant={
256262
account?.type
@@ -271,9 +277,9 @@ export const Profile = (): JSX.Element => {
271277
<IconTabs
272278
aria-label={_(msg`public profile tabs`)}
273279
tabs={tabs}
274-
linkComponent={Link}
275280
activeTab={activeTab}
276281
mobileFullWidth
282+
linkComponent={ReactRouterMuiLink}
277283
/>
278284
<div className="flex w-full md:w-auto mt-[30px] mb-7.5 md:mt-0 md:mb-0">
279285
{manageButtonConfig.map(

0 commit comments

Comments
 (0)