Skip to content

Commit b95e96b

Browse files
committed
change editTeam form
1 parent f06ebc8 commit b95e96b

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

components/edit-team-form.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function renderErrors (errors) {
2929
})
3030
}
3131

32-
export default function EditTeamForm ({ initialValues, onSubmit, staff, isCreateForm, extraTags = [], profileValues }) {
32+
export default function EditTeamForm ({ initialValues, onSubmit, staff, isCreateForm, orgTeamTags = [], teamTags = [], profileValues }) {
3333
if (profileValues) {
3434
initialValues.tags = {}
3535
profileValues.forEach(({ id, value }) => {
@@ -42,14 +42,34 @@ export default function EditTeamForm ({ initialValues, onSubmit, staff, isCreate
4242
onSubmit={onSubmit}
4343
render={({ status, isSubmitting, submitForm, values, errors, setFieldValue, setErrors, setStatus }) => {
4444
let uniqueOrgs
45-
let extraFields
45+
let extraOrgTeamFields = []
46+
let extraTeamFields = []
4647
if (staff && isCreateForm) {
4748
uniqueOrgs = uniqBy(prop('organization_id'), staff.map(({ name, organization_id }) => {
4849
return { name, organization_id }
4950
}))
5051
}
51-
if (extraTags.length > 0) {
52-
extraFields = extraTags.map(({ id, name, required, description }) => {
52+
if (orgTeamTags.length > 0) {
53+
extraOrgTeamFields = orgTeamTags.map(({ id, name, required, description }) => {
54+
return (
55+
<div className='form-control form-control__vertical' key={`extra-tag-${id}`}>
56+
<label htmlFor={`extra-tag-${id}`}>{name}
57+
{required ? <span className='form--required'>*</span> : ''}
58+
{description ? descriptionPopup(description) : ''}
59+
</label>
60+
<Field
61+
type='text'
62+
name={`tags.key-${id}`}
63+
required={required}
64+
value={values.tags[`key-${id}`]}
65+
/>
66+
</div>
67+
)
68+
})
69+
}
70+
71+
if (teamTags.length > 0) {
72+
extraTeamFields = teamTags.map(({ id, name, required, description }) => {
5373
return (
5474
<div className='form-control form-control__vertical' key={`extra-tag-${id}`}>
5575
<label htmlFor={`extra-tag-${id}`}>{name}
@@ -112,10 +132,17 @@ export default function EditTeamForm ({ initialValues, onSubmit, staff, isCreate
112132
)
113133
: ''
114134
}
115-
{extraTags.length > 0
135+
{extraOrgTeamFields.length > 0
116136
? <>
117137
<h2>Org Attributes</h2>
118-
{extraFields}
138+
{extraOrgTeamFields}
139+
</>
140+
: ''
141+
}
142+
{extraTeamFields.length > 0
143+
? <>
144+
<h2>Other Team Attributes</h2>
145+
{extraTeamFields}
119146
</>
120147
: ''
121148
}

pages/team-edit.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import getConfig from 'next/config'
77
import EditTeamForm from '../components/edit-team-form'
88
import Button from '../components/button'
99
import theme from '../styles/theme'
10-
import { getTeamAttributes, getTeamProfile } from '../lib/profiles-api'
10+
import { getOrgTeamAttributes, getTeamAttributes, getTeamProfile } from '../lib/profiles-api'
1111
const { publicRuntimeConfig } = getConfig()
1212

1313
export default class TeamEdit extends Component {
@@ -32,13 +32,18 @@ export default class TeamEdit extends Component {
3232
const { id } = this.props
3333
try {
3434
let team = await getTeam(id)
35-
let teamAttributes = await getTeamAttributes(id)
35+
let teamAttributes = await getTeamAttributes(id) || []
36+
let orgTeamAttributes = []
3637
let profileValues = []
3738
profileValues = await getTeamProfile(id)
39+
if (team.org) {
40+
orgTeamAttributes = await getOrgTeamAttributes(team.org.organization_id)
41+
}
3842
this.setState({
3943
team,
4044
profileValues,
4145
teamAttributes,
46+
orgTeamAttributes,
4247
loading: false
4348
})
4449
} catch (e) {
@@ -109,7 +114,7 @@ export default class TeamEdit extends Component {
109114
}
110115

111116
render () {
112-
const { team, error, teamAttributes, profileValues } = this.state
117+
const { team, error, teamAttributes, orgTeamAttributes, profileValues } = this.state
113118

114119
if (error) {
115120
if (error.status >= 400 && error.status < 500) {
@@ -139,7 +144,8 @@ export default class TeamEdit extends Component {
139144
<EditTeamForm
140145
initialValues={pick(['name', 'bio', 'hashtag', 'editing_policy', 'location', 'privacy'], team)}
141146
profileValues={profileValues}
142-
extraTags={teamAttributes}
147+
teamTags={teamAttributes}
148+
orgTeamTags={orgTeamAttributes}
143149
onSubmit={async (values, actions) => {
144150
try {
145151
let tags = Object.keys(values.tags).map(key => {

0 commit comments

Comments
 (0)