-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gets ragequite working and makes forms more configurable'
- Loading branch information
Showing
8 changed files
with
173 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { ComponentProps } from 'react'; | ||
import { Link as RouterLink } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
import { Button } from '@daohaus/ui'; | ||
|
||
type ProfileLinkProps = { | ||
href?: string; | ||
to: string; | ||
selected?: boolean; | ||
disabled?: boolean; | ||
linkType?: 'internal' | 'external' | 'no-icon-external'; | ||
hideIcon?: boolean; | ||
target?: string; | ||
rel?: string; | ||
} & Partial<ComponentProps<typeof Button>>; | ||
|
||
const StyledRouterLink = styled(RouterLink)` | ||
text-decoration: none; | ||
color: unset; | ||
&:hover { | ||
text-decoration: none; | ||
} | ||
`; | ||
|
||
export const ButtonRouterLink = ({ | ||
to, | ||
target, | ||
disabled, | ||
children, | ||
linkType, | ||
hideIcon, | ||
rel, | ||
...buttonProps | ||
}: ProfileLinkProps) => { | ||
return ( | ||
<StyledRouterLink to={to} target={target} className="button-link" rel={rel}> | ||
<Button disabled={disabled} {...buttonProps}> | ||
{children} | ||
</Button> | ||
</StyledRouterLink> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useMemo } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { FormBuilder } from '@daohaus/form-builder'; | ||
import { COMMON_FORMS } from '@daohaus/moloch-v3-legos'; | ||
import { MolochV3Dao } from '@daohaus/moloch-v3-data'; | ||
import { useCurrentDao, useDaoData } from '@daohaus/moloch-v3-hooks'; | ||
|
||
import { AppFieldLookup } from '../legos/legoConfig'; | ||
|
||
export const formatDaoProfileForForm = (dao: MolochV3Dao) => { | ||
const links = dao?.links || []; | ||
|
||
return { | ||
name: dao?.name, | ||
icon: dao?.avatarImg, | ||
tags: dao?.tags?.join(', '), | ||
description: dao?.description, | ||
long_description: dao?.longDescription, | ||
discord: links.find((link) => link.label === 'Discord')?.url, | ||
github: links.find((link) => link.label === 'Github')?.url, | ||
telegram: links.find((link) => link.label === 'Telegram')?.url, | ||
twitter: links.find((link) => link.label === 'Twitter')?.url, | ||
blog: links.find((link) => link.label === 'Blog')?.url, | ||
web: links.find((link) => link.label === 'Web')?.url, | ||
custom1: links[6]?.url, | ||
custom1Label: links[6]?.label, | ||
custom2: links[7]?.url, | ||
custom2Label: links[7]?.label, | ||
custom3: links[8]?.url, | ||
custom3Label: links[8]?.label, | ||
}; | ||
}; | ||
|
||
export function UpdateSettings() { | ||
const { dao, refetch } = useDaoData(); | ||
const { daoId, daoChain } = useCurrentDao(); | ||
const navigate = useNavigate(); | ||
|
||
const defaultFields = useMemo(() => { | ||
if (dao) { | ||
return formatDaoProfileForForm(dao); | ||
} | ||
return undefined; | ||
}, [dao]); | ||
|
||
const onFormComplete = () => { | ||
refetch?.(); | ||
navigate(`/molochV3/${daoChain}/${daoId}/settings`); | ||
}; | ||
|
||
if (!dao) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<FormBuilder | ||
defaultValues={defaultFields} | ||
form={{ ...COMMON_FORMS.METADATA_SETTINGS }} | ||
customFields={AppFieldLookup} | ||
targetNetwork={daoChain} | ||
lifeCycleFns={{ | ||
onPollSuccess: () => { | ||
onFormComplete(); | ||
}, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export default UpdateSettings; |