Skip to content

Commit

Permalink
[add] Type package, RESTful API & JWT middleware of OHP back-end v6 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery authored Aug 15, 2024
1 parent 7c6b026 commit 40a2980
Show file tree
Hide file tree
Showing 60 changed files with 722 additions and 462 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NEXT_PUBLIC_SITE_NAME = 开放黑客松
NEXT_PUBLIC_SITE_SUMMARY = 基于 Git 云开发环境的开放黑客马拉松平台
NEXT_PUBLIC_API_HOST = https://hackathon-api-test.kaiyuanshe.cn/v2/
NEXT_PUBLIC_API_HOST = https://openhackathon-service-server.onrender.com
NEXT_PUBLIC_AUTHING_APP_ID = 60178760106d5f26cb267ac1
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_API_HOST = http://127.0.0.1:8080
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Open-source [Hackathon][1] Platform with **Git-based Cloud Development Environme
- [Task kanban](https://github.com/orgs/kaiyuanshe/projects/9/)
- [UI design](https://www.figma.com/file/HKPV8IB4kxrAVAuuSBZKd1/Open-Hackathon)
- Web entry
- testing: https://open-hackathon.vercel.app/
- testing: https://test.hackathon.kaiyuanshe.cn/
- production: https://hackathon.kaiyuanshe.cn/
- RESTful API
- production: https://hackathon-server.kaiyuanshe.cn/documentation/
- production: https://openhackathon-service-server.onrender.com/

## Technology stack

Expand Down
4 changes: 2 additions & 2 deletions components/Activity/ActivityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import {
faTags,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Hackathon } from '@kaiyuanshe/openhackathon-service';
import classNames from 'classnames';
import { Card, Col, Row } from 'react-bootstrap';

import { Activity } from '../../models/Activity';
import { i18n } from '../../models/Base/Translation';
import { convertDatetime } from '../../utils/time';
import { ActivityControl, ActivityControlProps } from './ActivityControl';
import { ActivityEntry } from './ActivityEntry';

const { t } = i18n;

export interface ActivityCardProps extends Activity, ActivityControlProps {
export interface ActivityCardProps extends Hackathon, ActivityControlProps {
className?: string;
controls?: boolean;
}
Expand Down
4 changes: 2 additions & 2 deletions components/Activity/ActivityControl.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Hackathon } from '@kaiyuanshe/openhackathon-service';
import { observer } from 'mobx-react';
import { FC } from 'react';
import { Button } from 'react-bootstrap';

import { Activity } from '../../models/Activity';
import { i18n } from '../../models/Base/Translation';
import platformAdmin from '../../models/User/PlatformAdmin';

const { t } = i18n;

export interface ActivityControlProps
extends Pick<Activity, 'name' | 'status'> {
extends Pick<Hackathon, 'name' | 'status'> {
onPublish?: (name: string) => any;
onDelete?: (name: string) => any;
}
Expand Down
5 changes: 3 additions & 2 deletions components/Activity/ActivityEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Hackathon } from '@kaiyuanshe/openhackathon-service';
import { Loading } from 'idea-react';
import { observable } from 'mobx';
import { textJoin } from 'mobx-i18n';
Expand All @@ -8,15 +9,15 @@ import { FormEvent, PureComponent } from 'react';
import { Button, Col, Form, Row } from 'react-bootstrap';
import { formToJSON } from 'web-utility';

import activityStore, { Activity } from '../../models/Activity';
import activityStore from '../../models/Activity';
import fileStore from '../../models/Base/File';
import { i18n } from '../../models/Base/Translation';
import { DateTimeInput } from '../DateTimeInput';

const { t } = i18n,
HTMLEditor = dynamic(() => import('../HTMLEditor'), { ssr: false });

interface ActivityFormData extends Activity {
interface ActivityFormData extends Hackathon {
bannerUrls: string[] | string;
}

Expand Down
4 changes: 2 additions & 2 deletions components/Activity/ActivityEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Hackathon } from '@kaiyuanshe/openhackathon-service';
import { FC } from 'react';
import { Button } from 'react-bootstrap';
import { diffTime } from 'web-utility';

import { Activity } from '../../models/Activity';
import { i18n } from '../../models/Base/Translation';

const { t } = i18n;

export type ActivityStatusMeta = Pick<
Activity,
Hackathon,
| 'status'
| 'enrollmentStartedAt'
| 'enrollmentEndedAt'
Expand Down
11 changes: 4 additions & 7 deletions components/Activity/ActivityList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Hackathon } from '@kaiyuanshe/openhackathon-service';
import { ScrollList } from 'mobx-restful-table';
import { FC, PureComponent } from 'react';
import { Col, Row } from 'react-bootstrap';

import {
Activity,
ActivityListType,
ActivityModel,
} from '../../models/Activity';
import { ActivityListType, ActivityModel } from '../../models/Activity';
import { i18n } from '../../models/Base/Translation';
import platformAdmin from '../../models/User/PlatformAdmin';
import sessionStore from '../../models/User/Session';
Expand All @@ -16,11 +13,11 @@ import { ActivityCard, ActivityCardProps } from './ActivityCard';
const { t } = i18n;

export interface ActivityListLayoutProps
extends XScrollListProps<Activity>,
extends XScrollListProps<Hackathon>,
Pick<ActivityCardProps, 'onPublish' | 'onDelete'> {
type?: ActivityListType;
size?: 'sm' | 'lg';
userId?: string;
userId?: number;
}

export const ActivityListLayout: FC<ActivityListLayoutProps> = ({
Expand Down
8 changes: 4 additions & 4 deletions components/Activity/AwardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { XScrollListProps } from '../layout/ScrollList';
const { t } = i18n;

export interface AwardListLayoutProps extends XScrollListProps<Award> {
onEdit?: (id: string) => any;
onDelete?: (id: string) => any;
onEdit?: (id: number) => any;
onDelete?: (id: number) => any;
}

export const AwardTargetName = () => ({
Expand Down Expand Up @@ -84,12 +84,12 @@ export type AwardListProps = Pick<ScrollListProps<Award>, 'store'> &
AwardListLayoutProps;

export class AwardList extends PureComponent<AwardListProps> {
onEdit = (id: string) => {
onEdit = (id: number) => {
this.props.onEdit?.(id);
this.props.store.getOne(id);
};

onDelete = (id: string) => {
onDelete = (id: number) => {
if (!confirm(t('sure_delete_this_work'))) return;

this.props.onDelete?.(id);
Expand Down
2 changes: 1 addition & 1 deletion components/Activity/EnrollmentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { t } = i18n;
export interface EnrollmentListLayoutProps
extends XScrollListProps<Enrollment> {
onPopUp?: (extensions: Enrollment['extensions']) => any;
onVerify?: (userId: string, status: Enrollment['status']) => any;
onVerify?: (userId: number, status: Enrollment['status']) => any;
}

export const EnrollmentListLayout: FC<EnrollmentListLayoutProps> = ({
Expand Down
2 changes: 1 addition & 1 deletion components/Git/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const GitCard: FC<GitCardProps> = observer(
className="d-flex align-items-center"
style={{ gap: '0.5rem' }}
type="radio"
id={id}
id={id + ''}
name="template"
value={name}
label={t('select')}
Expand Down
20 changes: 10 additions & 10 deletions components/Message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const { t } = i18n;

export interface MessageListLayoutProps extends XScrollListProps<Message> {
hideControls?: boolean;
onEdit?: (id: string) => any;
onDelete?: (id: string) => any;
onEdit?: (id: number) => any;
onDelete?: (id: number) => any;
}

export const MessageListLayout: FC<MessageListLayoutProps> = ({
Expand Down Expand Up @@ -53,7 +53,7 @@ export const MessageListLayout: FC<MessageListLayoutProps> = ({
onSelect?.(
selectedIds.length === defaultData.length
? []
: defaultData.map(({ id }) => id + ''),
: defaultData.map(({ id }) => id),
)
}
/>
Expand All @@ -72,13 +72,13 @@ export const MessageListLayout: FC<MessageListLayoutProps> = ({
inline
type="checkbox"
name="announcementId"
checked={selectedIds?.includes(id + '')}
checked={selectedIds?.includes(id)}
onClick={
onSelect &&
(({ currentTarget: { checked } }) => {
if (checked) return onSelect([...selectedIds, id + '']);
if (checked) return onSelect([...selectedIds, id]);

const index = selectedIds.indexOf(id + '');
const index = selectedIds.indexOf(id);

onSelect([
...selectedIds.slice(0, index),
Expand Down Expand Up @@ -116,17 +116,17 @@ export type MessageListProps = Pick<ScrollListProps<Message>, 'store'> &
@observer
export class MessageList extends PureComponent<MessageListProps> {
@observable
accessor selectedIds: string[] = [];
accessor selectedIds: number[] = [];

onSelect = (list: string[]) =>
onSelect = (list: number[]) =>
(this.selectedIds = list) && this.props.onSelect?.(list);

onEdit = (id: string) => {
onEdit = (id: number) => {
this.props.onEdit?.(id);
this.props.store.getOne(id);
};

onDelete = (id: string) => {
onDelete = (id: number) => {
if (!confirm(t('sure_delete_this_message'))) return;

this.props.onDelete?.(id);
Expand Down
8 changes: 4 additions & 4 deletions components/Organization/OrganizationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const OrganizationTableLayout: FC<XScrollListProps<Organization>> = ({
onSelect?.(
selectedIds.length === defaultData.length
? []
: defaultData.map(({ id }) => String(id)),
: defaultData.map(({ id }) => id),
)
}
/>
Expand All @@ -70,13 +70,13 @@ export const OrganizationTableLayout: FC<XScrollListProps<Organization>> = ({
inline
type="checkbox"
name="organizationId"
checked={selectedIds?.includes(String(id))}
checked={selectedIds?.includes(id)}
onClick={
onSelect &&
(({ currentTarget: { checked } }) => {
if (checked) return onSelect([...selectedIds, String(id)]);
if (checked) return onSelect([...selectedIds, id]);

const index = selectedIds.indexOf(String(id));
const index = selectedIds.indexOf(id);

onSelect([
...selectedIds.slice(0, index),
Expand Down
2 changes: 1 addition & 1 deletion components/PlatformAdmin/PlatformAdminModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface PlatformAdminModalProps
@observer
export class PlatformAdminModal extends PureComponent<PlatformAdminModalProps> {
@observable
accessor userId = '';
accessor userId = 0;

increaseId = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
Expand Down
4 changes: 2 additions & 2 deletions components/Team/TeamAdministratorTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const { t } = i18n;

export interface TeamAdministratorTableLayoutProps
extends XScrollListProps<TeamMember> {
onUpdateRole?: (userId: string, role: 'admin' | 'member') => any;
onPopUpUpdateRoleModal?: (userId: string) => any;
onUpdateRole?: (userId: number, role: 'admin' | 'member') => any;
onPopUpUpdateRoleModal?: (userId: number) => any;
}

const TableHeads = () => [
Expand Down
4 changes: 2 additions & 2 deletions components/Team/TeamAwardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export interface TeamAwardCardProps
| 'id'
> {
className?: string;
onAssign: (id: string) => any;
onDelete?: (id: string) => any;
onAssign: (id: number) => any;
onDelete?: (id: number) => any;
}

export class TeamAwardCard extends PureComponent<TeamAwardCardProps> {
Expand Down
4 changes: 2 additions & 2 deletions components/Team/TeamAwardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export type TeamAwardListProps = Pick<ScrollListProps<Team>, 'store'> &
TeamAwardListLayoutProps;

export class TeamAwardList extends PureComponent<TeamAwardListProps> {
onAssign = (id: string) => {
onAssign = (id: number) => {
this.props.onAssign?.(id);
this.props.store.getOne(id);
};

onDelete = (id: string) => {
onDelete = (id: number) => {
if (!confirm(t('sure_delete_this_work'))) return;

this.props.onDelete?.(id);
Expand Down
9 changes: 7 additions & 2 deletions components/Team/TeamCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import { i18n } from '../../models/Base/Translation';

const { t } = i18n;

export type TeamCardProps = HTMLAttributes<HTMLDivElement> &
export type TeamCardProps = Omit<HTMLAttributes<HTMLDivElement>, 'id'> &
Pick<
Team,
'hackathonName' | 'displayName' | 'creatorId' | 'creator' | 'membersCount'
| 'id'
| 'hackathonName'
| 'displayName'
| 'creatorId'
| 'creator'
| 'membersCount'
>;

export const TeamCard: FC<TeamCardProps> = ({
Expand Down
2 changes: 1 addition & 1 deletion components/Team/TeamManageFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type TeamManageBaseParams = Record<'name' | 'tid', string>;
export type TeamManageBaseProps = RouteProps<TeamManageBaseParams> & JWTProps;

export interface TeamManageFrameProps extends ActivityManageFrameProps {
tid: string;
tid: number;
}

@observer
Expand Down
2 changes: 1 addition & 1 deletion components/Team/TeamParticipantTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { t } = i18n;

export interface TeamParticipantTableLayoutProps
extends XScrollListProps<TeamMember> {
onApprove?: (userId: string, status: MembershipStatus) => any;
onApprove?: (userId: number, status: MembershipStatus) => any;
}

const StatusName: () => Record<TeamMember['status'], string> = () => ({
Expand Down
8 changes: 5 additions & 3 deletions components/Team/TeamWorkList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { XScrollListProps } from '../layout/ScrollList';

const { t } = i18n;

export interface TeamWorkCardProps extends TeamWork, Omit<CardProps, 'title'> {
export interface TeamWorkCardProps
extends TeamWork,
Omit<CardProps, 'id' | 'title'> {
controls?: boolean;
onDelete?: (id: TeamWork['id']) => any;
}
Expand Down Expand Up @@ -85,7 +87,7 @@ export interface TeamWorkListLayoutProps
extends XScrollListProps<TeamWork>,
Pick<TeamWorkCardProps, 'controls' | 'onDelete'> {
activity: string;
team: string;
team: number;
size?: 'sm' | 'lg';
}

Expand Down Expand Up @@ -129,7 +131,7 @@ export const TeamWorkListLayout: FC<TeamWorkListLayoutProps> = observer(
export class TeamWorkList extends PureComponent<TeamWorkListLayoutProps> {
store = activityStore.teamOf(this.props.activity).workOf(this.props.team);

onDelete = (id?: string) =>
onDelete = (id?: number) =>
id && confirm(t('confirm_delete_work')) && this.store.deleteOne(id);

render() {
Expand Down
6 changes: 5 additions & 1 deletion components/Team/WorkEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { i18n } from '../../models/Base/Translation';

const { t } = i18n;

export type WorkEditorProps = Record<'name' | 'tid', string> & { wid?: string };
export interface WorkEditorProps {
name: string;
tid: number;
wid?: string;
}

@observer
export class WorkEditor extends PureComponent<WorkEditorProps> {
Expand Down
2 changes: 1 addition & 1 deletion components/User/ActivityAdministratorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface AdministratorModalProps
@observer
export class AdministratorModal extends PureComponent<AdministratorModalProps> {
@observable
accessor userId = '';
accessor userId = 0;

increaseId = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
Expand Down
Loading

1 comment on commit 40a2980

@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-1pgjmx6yq-techquerys-projects.vercel.app

Built with commit 40a2980.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.