Skip to content

Commit

Permalink
[optimize] simplify Questionnaire types
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Aug 29, 2024
1 parent 414d1c6 commit 240454e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
4 changes: 0 additions & 4 deletions models/Activity/Question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export interface Question {
required?: boolean;
}

export interface Extensions {
name: string;
value: string;
}
export const questions: Question[] = [
{
title: t('what_is_your_occupation'),
Expand Down
14 changes: 5 additions & 9 deletions models/Activity/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
Base,
Enrollment,
Extension,
Hackathon,
HackathonStatus,
Questionnaire,
} from '@kaiyuanshe/openhackathon-service';
import { action, observable } from 'mobx';
import { toggle } from 'mobx-restful';
Expand All @@ -16,7 +17,7 @@ import { EnrollmentModel } from './Enrollment';
import { LogModel } from './Log';
import { AnnouncementModel } from './Message';
import { OrganizerModel } from './Organization';
import { Extensions, Question } from './Question';
import { Question } from './Question';
import { StaffModel } from './Staff';
import { TeamModel } from './Team';

Expand Down Expand Up @@ -44,11 +45,6 @@ export interface ActivityLogsFilter extends Filter<Hackathon> {
name: string;
}

export interface Questionnaire extends Base {
extensions: Extensions[];
hackathonName: string;
}

export class ActivityModel extends TableModel<Hackathon, ActivityFilter> {
baseURI = 'hackathon';
indexKey = 'name' as const;
Expand Down Expand Up @@ -171,7 +167,7 @@ export class ActivityModel extends TableModel<Hackathon, ActivityFilter> {

@toggle('uploading')
createQuestionnaire(
extensions: Extensions[],
extensions: Extension[],
activity = this.currentOne.name,
) {
return this.client.put(`${this.baseURI}/${activity}/questionnaire`, {
Expand All @@ -181,7 +177,7 @@ export class ActivityModel extends TableModel<Hackathon, ActivityFilter> {

@toggle('uploading')
updateQuestionnaire(
extensions: Extensions[],
extensions: Extension[],
activity = this.currentOne.name,
) {
return this.client.patch(`${this.baseURI}/${activity}/questionnaire`, {
Expand Down
7 changes: 3 additions & 4 deletions pages/activity/[name]/manage/questionnaire.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Extension } from '@kaiyuanshe/openhackathon-service';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import {
Expand All @@ -16,7 +17,7 @@ import { QuestionnaireForm } from '../../../../components/Activity/Questionnaire
import { QuestionnaireTable } from '../../../../components/Activity/QuestionnaireTable';
import { ServerSessionBox } from '../../../../components/User/ServerSessionBox';
import activityStore from '../../../../models/Activity';
import { Extensions, Question } from '../../../../models/Activity/Question';
import { Question } from '../../../../models/Activity/Question';
import { isServer } from '../../../../models/Base';
import { i18n } from '../../../../models/Base/Translation';

Expand Down Expand Up @@ -68,7 +69,7 @@ class ActivityQuestionnaireEditor extends PureComponent<ActivityQuestionnairePag

if (!questionnaire[0]) return self.alert(t('please_add_question'));

const questions: Extensions[] = questionnaire.map(v => ({
const questions: Extension[] = questionnaire.map(v => ({
name: v.id || v.title,
value: JSON.stringify(v),
}));
Expand All @@ -78,13 +79,11 @@ class ActivityQuestionnaireEditor extends PureComponent<ActivityQuestionnairePag
} else {
await activityStore.updateQuestionnaire(questions, this.activity);
}

self.alert(
this.isCreate
? t('create_questionnaire_success')
: t('update_questionnaire_success'),
);

this.isCreate = false;
};

Expand Down
13 changes: 4 additions & 9 deletions pages/activity/[name]/register.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Extension } from '@kaiyuanshe/openhackathon-service';
import { textJoin } from 'mobx-i18n';
import { observer } from 'mobx-react';
import {
Expand All @@ -16,7 +17,7 @@ import { QuestionnaireForm } from '../../../components/Activity/QuestionnairePre
import { PageHead } from '../../../components/layout/PageHead';
import { ServerSessionBox } from '../../../components/User/ServerSessionBox';
import activityStore, { ActivityModel } from '../../../models/Activity';
import { Extensions, Question } from '../../../models/Activity/Question';
import { Question } from '../../../models/Activity/Question';
import { i18n } from '../../../models/Base/Translation';

const { t } = i18n;
Expand Down Expand Up @@ -53,14 +54,8 @@ export default class RegisterPage extends PureComponent<RegisterPageProps> {
data = formToJSON(event.target as HTMLFormElement);

const extensions = Object.entries(data)
.map(
([name, value]) =>
value && {
name,
value: value + '',
},
)
.filter(Boolean) as Extensions[];
.map(([name, value]) => value && { name, value: value + '' })
.filter(Boolean) as Extension[];

await activityStore.signOne(activity, extensions);

Expand Down

1 comment on commit 240454e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for open-hackathon ready!

✅ Preview
https://open-hackathon-cuy72e4pc-techquerys-projects.vercel.app

Built with commit 240454e.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.