Skip to content

Commit

Permalink
rearranging FORM into seperrate objects (#769)
Browse files Browse the repository at this point in the history
* rearranging FORM into seperrate objects

* adding comment for form keys

* clenaup
  • Loading branch information
brossetti1 authored Aug 31, 2022
1 parent ee49b38 commit 3f15597
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 50 deletions.
99 changes: 54 additions & 45 deletions apps/core-app/src/legos/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,36 @@ import { TABULA_TX, TX } from './tx';
export const getFormLegoById = (
id: CustomFormLego['id']
): CustomFormLego | undefined => {
const formKey = Object.keys(FORM).find((key) => {
return FORM[key].id === id;
const formKey = Object.keys(PROPOSAL_FORMS).find((key) => {
return PROPOSAL_FORMS[key].id === id;
});
if (!formKey) return;
return FORM[formKey];
return PROPOSAL_FORMS[formKey];
};

export const FORM: Record<string, CustomFormLego> = {
/*
Quick Reference for forms
PROPOSAL_FORMS KEYS
- SHARE_SWAP
- SIGNAL
- ISSUE
- ADD_SHAMAN
- UPDATE_SHAMAN
- ISSUE_ERC20
- ISSUE_NETWORK_TOKEN
- UPDATE_GOV_SETTINGS
- TOKEN_SETTINGS
- TOKENS_FOR_SHARES
- GUILDKICK
- CREATE_PUBLICATION
- CREATE_ARTICLE
COMMON_FORMS KEYS
- METADATA_SETTINGS
*/

export const PROPOSAL_FORMS: Record<string, CustomFormLego> = {
SHARE_SWAP: {
id: 'SHARE_SWAP',
title: 'Swap Tokens for Shares',
Expand Down Expand Up @@ -109,22 +131,6 @@ export const FORM: Record<string, CustomFormLego> = {
FIELD.SHAMAN_DELUXE,
],
},
TEST: {
id: 'TEST',
title: 'Test Form',
subtitle: 'Test Proposal',
description:
'Test your proposal like a champ with this shiny new Test Form.',
requiredFields: { title: true, description: true },
log: true,
tx: TX.POST_SIGNAL,
fields: [
FIELD.TITLE,
FIELD.DESCRIPTION,
FIELD.LINK,
FIELD.REQUEST_NATIVE_TOKEN,
],
},
ISSUE_ERC20: {
id: 'ISSUE_ERC20',
title: 'Issue Funding (ERC20)',
Expand Down Expand Up @@ -179,31 +185,6 @@ export const FORM: Record<string, CustomFormLego> = {
FIELD.REQUEST_NATIVE_TOKEN,
],
},
METADATA_SETTINGS: {
id: 'METADATA_SETTINGS',
title: 'Update Metadata Settings',
subtitle: 'Settings',
requiredFields: { name: true },
log: true,
tx: TX.UPDATE_METADATA_SETTINGS,
fields: [
FIELD.NAME,
FIELD.DESCRIPTION,
{
...FIELD.DESCRIPTION,
id: 'long_description',
label: 'Long Description',
},
{ ...FIELD.LINK, id: 'icon', label: 'Icon' },
{ ...FIELD.LINK, id: 'discord', label: 'Discord' },
{ ...FIELD.LINK, id: 'github', label: 'Github' },
{ ...FIELD.LINK, id: 'medium', label: 'Medium' },
{ ...FIELD.LINK, id: 'telegram', label: 'Telegram' },
{ ...FIELD.LINK, id: 'twitter', label: 'Twitter' },
{ ...FIELD.LINK, id: 'other', label: 'Other' },
FIELD.TAGS,
],
},
UPDATE_GOV_SETTINGS: {
id: 'UPDATE_GOV_SETTINGS',
title: 'Update Governance Settings',
Expand Down Expand Up @@ -514,3 +495,31 @@ export const TABULA_FORMS: Record<string, CustomFormLego> = {
],
},
};

export const COMMON_FORMS = {
METADATA_SETTINGS: {
id: 'METADATA_SETTINGS',
title: 'Update Metadata Settings',
subtitle: 'Settings',
requiredFields: { name: true },
log: true,
tx: TX.UPDATE_METADATA_SETTINGS,
fields: [
FIELD.NAME,
FIELD.DESCRIPTION,
{
...FIELD.DESCRIPTION,
id: 'long_description',
label: 'Long Description',
},
{ ...FIELD.LINK, id: 'icon', label: 'Icon' },
{ ...FIELD.LINK, id: 'discord', label: 'Discord' },
{ ...FIELD.LINK, id: 'github', label: 'Github' },
{ ...FIELD.LINK, id: 'medium', label: 'Medium' },
{ ...FIELD.LINK, id: 'telegram', label: 'Telegram' },
{ ...FIELD.LINK, id: 'twitter', label: 'Twitter' },
{ ...FIELD.LINK, id: 'other', label: 'Other' },
FIELD.TAGS,
],
},
};
9 changes: 6 additions & 3 deletions apps/core-app/src/pages/Proposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { BsPlusLg } from 'react-icons/bs';

import { defaultDaoData, useDao, useProposals } from '../contexts/DaoContext';
import { NewProposalList } from '../components/NewProposalList';
import { FORM } from '../legos/form';
import { PROPOSAL_FORMS } from '../legos/form';
import SearchInput from '../components/SearchInput';
import FilterDropdown from '../components/FilterDropdown';
import { BaseProposalCard } from '../components/BaseProposalCard';
Expand All @@ -30,7 +30,10 @@ const SearchFilterContainer = styled.div`
gap: 2.1rem;
`;

export const VALID_NEW_PROPOSALS = [FORM.SIGNAL, FORM.SHARE_SWAP];
export const VALID_NEW_PROPOSALS = [
PROPOSAL_FORMS.SIGNAL,
PROPOSAL_FORMS.SHARE_SWAP,
];

export function Proposals() {
const {
Expand All @@ -45,7 +48,7 @@ export function Proposals() {
const [filter, setFilter] = useState<string>('');

const newProposals = useMemo(() => {
return Object.keys(FORM).map((key) => FORM[key]);
return Object.keys(PROPOSAL_FORMS).map((key) => PROPOSAL_FORMS[key]);
}, []);

const handleSearchFilter = (term: string) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/core-app/src/pages/UpdateSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FormBuilder } from '@daohaus/haus-form-builder';
import { useMemo } from 'react';
import { useDao } from '../contexts/DaoContext';
import { CustomFields } from '../legos/config';
import { FORM } from '../legos/form';
import { COMMON_FORMS } from '../legos/form';

export function UpdateSettings() {
const { dao } = useDao();
Expand All @@ -27,7 +27,7 @@ export function UpdateSettings() {
return (
<FormBuilder
defaultValues={defaultFields}
form={{ ...FORM.METADATA_SETTINGS, log: true }}
form={{ ...COMMON_FORMS.METADATA_SETTINGS, log: true }}
customFields={CustomFields}
/>
);
Expand Down

0 comments on commit 3f15597

Please sign in to comment.