Skip to content

Commit 488efdf

Browse files
committed
fix: solved isMentor not displaying in profile
1 parent dd13347 commit 488efdf

File tree

2 files changed

+229
-236
lines changed

2 files changed

+229
-236
lines changed

src/js/form.js

Lines changed: 109 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,143 @@
1-
import React from "react";
2-
import Form from "react-jsonschema-form";
3-
import API from "@aws-amplify/api";
4-
import Loading from "./loading";
5-
import { Redirect } from "react-router";
1+
import React from 'react';
2+
import Form from 'react-jsonschema-form';
3+
import API from '@aws-amplify/api';
4+
import Loading from './loading';
5+
import { Redirect } from 'react-router';
66

77
const schema = {
8-
title: "Tell us about yourself!",
9-
type: "object",
8+
title: 'Tell us about yourself!',
9+
type: 'object',
1010
required: [],
1111
properties: {
12-
profileDesc: { type: "string", title: "Profile Description" },
13-
idea: { type: "string", title: "Challenge ideas" },
12+
profileDesc: { type: 'string', title: 'Profile Description' },
13+
idea: { type: 'string', title: 'Challenge ideas' },
1414
verticals: {
1515
title: "Challenges I'm interested in",
16-
type: "array",
16+
type: 'array',
1717
uniqueItems: true,
1818
items: {
19-
type: "string",
19+
type: 'string',
2020
enum: [
21-
"Healthcare",
22-
"New Froniers",
23-
"Web 3.0 and Fintech",
24-
"Sustainability",
25-
"Education",
26-
"Privacy and Safety"
27-
]
28-
}
21+
'Healthcare',
22+
'New Froniers',
23+
'Web 3.0 and Fintech',
24+
'Sustainability',
25+
'Education',
26+
'Privacy and Safety',
27+
],
28+
},
2929
},
30-
pronouns: { type: "string", title: "Pronouns" },
30+
pronouns: { type: 'string', title: 'Pronouns' },
3131
skills: {
32-
title: "My Skills",
33-
type: "array",
32+
title: 'My Skills',
33+
type: 'array',
3434
uniqueItems: true,
3535
items: {
36-
type: "string",
36+
type: 'string',
3737
enum: [
38-
"AI",
39-
"Data Mining",
40-
"NLP",
41-
"Web Development",
42-
"IOS",
43-
"Android",
44-
"Pitching",
45-
"Marketing",
46-
"Design",
47-
"AR/VR",
48-
"Game Development",
49-
"Systems"
50-
]
51-
}
38+
'AI',
39+
'Data Mining',
40+
'NLP',
41+
'Web Development',
42+
'IOS',
43+
'Android',
44+
'Pitching',
45+
'Marketing',
46+
'Design',
47+
'AR/VR',
48+
'Game Development',
49+
'Systems',
50+
],
51+
},
5252
},
5353
userType: {
54-
title: "Profile Type",
55-
type: "string",
56-
default: "Hacker",
57-
enumNames: [
58-
"Hacker",
59-
"Mentor",
60-
],
61-
"enum": [
62-
"Hacker",
63-
"Mentor",
64-
]
54+
title: 'Profile Type',
55+
type: 'string',
56+
default: 'Hacker',
57+
enumNames: ['Hacker', 'Mentor'],
58+
enum: ['Hacker', 'Mentor'],
6559
},
6660
commitment: {
67-
title: "Commitment Level",
68-
type: "string",
61+
title: 'Commitment Level',
62+
type: 'string',
6963
enumNames: [
70-
"High - Shooting for a prize, will spend majority of time hacking",
71-
"Medium - Will submit a substantial project, but with long breaks (e.g lots of rest, workshops)",
72-
"Low - Wants to submit something, but won't spend majority of time hacking"
64+
'High - Shooting for a prize, will spend majority of time hacking',
65+
'Medium - Will submit a substantial project, but with long breaks (e.g lots of rest, workshops)',
66+
"Low - Wants to submit something, but won't spend majority of time hacking",
7367
],
74-
"enum": [
75-
"High",
76-
"Medium",
77-
"Low"
78-
]
68+
enum: ['High', 'Medium', 'Low'],
7969
},
8070
timezoneOffset: {
81-
title: "Timezone",
82-
type: "string",
83-
default: getTimezoneOffset()
71+
title: 'Timezone',
72+
type: 'string',
73+
default: getTimezoneOffset(),
8474
},
85-
githubLink: { type: "string", title: "GitHub Link" },
86-
linkedinLink: { type: "string", title: "Linkedin Link" },
87-
devpostLink: { type: "string", title: "Devpost Link" },
88-
portfolioLink: { type: "string", title: "Portfolio Link" },
75+
githubLink: { type: 'string', title: 'GitHub Link' },
76+
linkedinLink: { type: 'string', title: 'Linkedin Link' },
77+
devpostLink: { type: 'string', title: 'Devpost Link' },
78+
portfolioLink: { type: 'string', title: 'Portfolio Link' },
8979
showProfile: {
90-
type: "boolean",
91-
title: "Yes! Show my profile and allow other hackers to contact me.",
92-
default: true
93-
}
94-
}
80+
type: 'boolean',
81+
title: 'Yes! Show my profile and allow other hackers to contact me.',
82+
default: true,
83+
},
84+
},
9585
};
9686

9787
const uiSchema = {
9888
profileDesc: {
99-
"ui:widget": "textarea",
100-
"ui:placeholder":
101-
"Tell other hackers about yourself!"
89+
'ui:widget': 'textarea',
90+
'ui:placeholder': 'Tell other hackers about yourself!',
10291
},
10392
idea: {
104-
"ui:widget": "textarea",
105-
"ui:placeholder":
106-
"Pitch an idea that interests you! This will be shared on the ideas page."
93+
'ui:widget': 'textarea',
94+
'ui:placeholder':
95+
'Pitch an idea that interests you! This will be shared on the ideas page.',
10796
},
10897
pronouns: {
109-
"ui:placeholder":
110-
"Gender pronouns (optional)"
98+
'ui:placeholder': 'Gender pronouns (optional)',
11199
},
112100
verticals: {
113-
"ui:widget": "checkboxes"
101+
'ui:widget': 'checkboxes',
114102
},
115103
skills: {
116-
"ui:widget": "checkboxes"
104+
'ui:widget': 'checkboxes',
117105
},
118106
timezoneOffset: {
119-
"ui:description": "Enter your timezone in GMT e.g GMT +0230, GMT -1100"
107+
'ui:description': 'Enter your timezone in GMT e.g GMT +0230, GMT -1100',
120108
},
121109
userType: {
122-
"ui:description": "Are you a hacker vs mentor?",
110+
'ui:description': 'Are you a hacker vs mentor?',
123111
},
124112
commitment: {
125-
"ui:description": "What is your commitment level for TreeHacks 2023?"
113+
'ui:description': 'What is your commitment level for TreeHacks 2023?',
126114
},
127115
githubLink: {
128-
"ui:description": "Social Media Links:",
129-
"ui:placeholder":
130-
"GitHub Profile"
116+
'ui:description': 'Social Media Links:',
117+
'ui:placeholder': 'GitHub Profile',
131118
},
132119
linkedinLink: {
133-
"ui:placeholder":
134-
"Linkedin Profile"
120+
'ui:placeholder': 'Linkedin Profile',
135121
},
136122
devpostLink: {
137-
"ui:placeholder":
138-
"Devpost Profile"
123+
'ui:placeholder': 'Devpost Profile',
139124
},
140125
portfolioLink: {
141-
"ui:placeholder":
142-
"Portfolio Link"
126+
'ui:placeholder': 'Portfolio Link',
143127
},
144128
};
145129

146-
const log = type => console.log.bind(console, type);
130+
const log = (type) => console.log.bind(console, type);
147131

148132
// // Automatically calculate GMT timezone
149133
function getTimezoneOffset() {
150-
function z(n){return (n<10? '0' : '') + n}
134+
function z(n) {
135+
return (n < 10 ? '0' : '') + n;
136+
}
151137
var offset = new Date().getTimezoneOffset();
152-
var sign = offset < 0? '+' : '-';
138+
var sign = offset < 0 ? '+' : '-';
153139
offset = Math.abs(offset);
154-
return "GMT " + sign + z(offset/60 | 0) + z(offset%60);
140+
return 'GMT ' + sign + z((offset / 60) | 0) + z(offset % 60);
155141
}
156142

157143
function isValidGMT(userInp) {
@@ -165,40 +151,49 @@ class MeetForm extends React.Component {
165151
this.state = {
166152
formSchema: schema,
167153
dataFetched: false,
168-
redirect: false
154+
redirect: false,
169155
};
170156
}
171157

172158
async componentDidMount() {
173-
const meet_info = await API.get(
174-
"treehacks",
159+
var meet_info = await API.get(
160+
'treehacks',
175161
`/users/${this.props.user.username}/forms/meet_info`,
176162
{}
177163
);
178-
console.log("User: " + this.props.user.username);
164+
165+
meet_info = {
166+
...meet_info,
167+
userType: meet_info.isMentor ? 'Mentor' : 'Hacker',
168+
};
169+
179170
if (meet_info) {
180171
for (const index in meet_info) {
181-
if (!(index in this.state.formSchema["properties"])) continue;
182-
this.state.formSchema["properties"][index]["default"] =
172+
if (!(index in this.state.formSchema['properties'])) continue;
173+
this.state.formSchema['properties'][index]['default'] =
183174
meet_info[index];
184175
}
185176

186177
this.setState({
187178
formSchema: this.state.formSchema,
188-
dataFetched: true
179+
dataFetched: true,
189180
});
190181
}
191182
}
192183

193184
async submitForm(e) {
194-
const payload = { body: {...e.formData, isMentor: e.formData.userType === "Mentor"} }
195-
delete payload["body"]["userType"];
185+
const payload = {
186+
body: { ...e.formData, isMentor: e.formData.userType === 'Mentor' },
187+
};
188+
delete payload['body']['userType'];
196189

197-
if (isValidGMT(payload["body"]["timezoneOffset"]) == null) {
198-
alert("Please enter your GMT timezone in a valid format (e.g GMT +0800, GMT -1130)");
190+
if (isValidGMT(payload['body']['timezoneOffset']) == null) {
191+
alert(
192+
'Please enter your GMT timezone in a valid format (e.g GMT +0800, GMT -1130)'
193+
);
199194
} else {
200195
const resp = await API.put(
201-
"treehacks",
196+
'treehacks',
202197
`/users/${this.props.user.username}/forms/meet_info`,
203198
payload
204199
);
@@ -211,18 +206,17 @@ class MeetForm extends React.Component {
211206
//if (false) {
212207
if (!this.state.dataFetched) {
213208
return <Loading />;
214-
}
215-
else {
209+
} else {
216210
return (
217-
<div id="form">
211+
<div id='form'>
218212
<Form
219213
schema={this.state.formSchema}
220214
uiSchema={uiSchema}
221-
onChange={log("changed")}
222-
onSubmit={e => this.submitForm(e)}
223-
onError={log("errors")}
215+
onChange={log('changed')}
216+
onSubmit={(e) => this.submitForm(e)}
217+
onError={log('errors')}
224218
/>
225-
{this.state.redirect && <Redirect to="/" />}
219+
{this.state.redirect && <Redirect to='/' />}
226220
</div>
227221
);
228222
}

0 commit comments

Comments
 (0)