Skip to content

Commit f7b9c62

Browse files
committed
next/store/course license: set academic user value and hide period selection in form
1 parent 6f1a555 commit f7b9c62

File tree

3 files changed

+78
-42
lines changed

3 files changed

+78
-42
lines changed

src/.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"Bash(pnpm tsc:*)",
55
"Bash(pnpm build:*)",
66
"Bash(git add:*)",
7-
"Bash(git commit:*)"
7+
"Bash(git commit:*)",
8+
"Bash(prettier -w:*)"
89
],
910
"deny": []
1011
}

src/CLAUDE.md

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
# CoCalc Source Repository
66

7-
* This is the source code of CoCalc in a Git repository
8-
* It is a complex JavaScript/TypeScript SaaS application
9-
* CoCalc is organized as a monorepository (multi-packages) in the subdirectory "./packages"
10-
* The packages are managed as a pnpm workspace in "./packages/pnpm-workspace.yaml"
7+
- This is the source code of CoCalc in a Git repository
8+
- It is a complex JavaScript/TypeScript SaaS application
9+
- CoCalc is organized as a monorepository (multi-packages) in the subdirectory "./packages"
10+
- The packages are managed as a pnpm workspace in "./packages/pnpm-workspace.yaml"
1111

1212
## Code Style
1313

1414
- Everything is written in TypeScript code
1515
- Indentation: 2-spaces
16+
- Run `pretter -w [filename]` after modifying a file (ts, tsx, md, json, ...) to format it correctly.
1617
- All .js and .ts files are formatted by the tool prettier
1718
- Add suitable types when you write code
1819
- Variable name styles are "camelCase" for local and "FOO_BAR" for global variables. If you edit older code not following these guidlines, adjust this rule to fit the files style.
@@ -23,28 +24,32 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
2324
## Development Commands
2425

2526
### Essential Commands
27+
2628
- `pnpm build-dev` - Build all packages for development
2729
- `pnpm clean` - Clean all node_modules and dist directories
28-
- `pnpm database` - Start PostgreSQL database server
29-
- `pnpm hub` - Start the main hub server
30-
- `pnpm psql` - Connect to the PostgreSQL database
3130
- `pnpm test` - Run full test suite
32-
- `pnpm test-parallel` - Run tests in parallel across packages
3331
- `pnpm depcheck` - Check for dependency issues
32+
- `prettier -w [filename]` to format the style of a file after editing it
33+
- after creating a file, run `git add [filename]` to start tracking it
3434

3535
### Package-Specific Commands
36-
- `cd packages/[package] && pnpm tsc` - Watch TypeScript compilation for a specific package
36+
37+
- `cd packages/[package] && pnpm build` - Build and compile a specific package
38+
- for packages/next and packages/static, run `cd packages/[package] && pnpm build-dev`
39+
- `cd packages/[package] && pnpm tsc:watch` - TypeScript compilation in watch mode for a specific package
3740
- `cd packages/[package] && pnpm test` - Run tests for a specific package
3841
- `cd packages/[package] && pnpm build` - Build a specific package
42+
- **IMPORTANT**: When modifying packages like `util` that other packages depend on, you must run `pnpm build` in the modified package before typechecking dependent packages
3943

40-
### Development Setup
41-
1. Start database: `pnpm database`
42-
2. Start hub: `pnpm hub`
43-
3. For TypeScript changes, run `pnpm tsc` in the relevant package directory
44+
### Development
45+
46+
- After code changes, run `pretter -w [filename]` to ensure consistent styling
47+
- After TypeScript or `*.tsx` changes, run `pnpm build` in the relevant package directory
4448

4549
## Architecture Overview
4650

4751
### Package Structure
52+
4853
CoCalc is organized as a monorepo with key packages:
4954

5055
- **frontend** - React/TypeScript frontend application using Redux-style stores and actions
@@ -62,25 +67,29 @@ CoCalc is organized as a monorepo with key packages:
6267
### Key Architectural Patterns
6368

6469
#### Frontend Architecture
70+
6571
- **Redux-style State Management**: Uses custom stores and actions pattern (see `packages/frontend/app-framework/actions-and-stores.ts`)
6672
- **TypeScript React Components**: All frontend code is TypeScript with proper typing
6773
- **Modular Store System**: Each feature has its own store/actions (AccountStore, BillingStore, etc.)
6874
- **WebSocket Communication**: Real-time communication with backend via WebSocket messages
6975

7076
#### Backend Architecture
77+
7178
- **PostgreSQL Database**: Primary data store with sophisticated querying system
7279
- **WebSocket Messaging**: Real-time communication between frontend and backend
7380
- **Conat System**: Container orchestration for compute servers
7481
- **Event-Driven Architecture**: Extensive use of EventEmitter patterns
7582
- **Microservice-like Packages**: Each package handles specific functionality
7683

7784
#### Communication Patterns
85+
7886
- **WebSocket Messages**: Primary communication method (see `packages/comm/websocket/types.ts`)
7987
- **Database Queries**: Structured query system with typed interfaces
8088
- **Event Emitters**: Inter-service communication within backend
8189
- **REST-like APIs**: Some HTTP endpoints for specific operations
8290

8391
### Key Technologies
92+
8493
- **TypeScript**: Primary language for all new code
8594
- **React**: Frontend framework
8695
- **PostgreSQL**: Database
@@ -91,40 +100,56 @@ CoCalc is organized as a monorepo with key packages:
91100
- **SASS**: CSS preprocessing
92101

93102
### Database Schema
103+
94104
- Comprehensive schema in `packages/util/db-schema`
95105
- Query abstractions in `packages/database/postgres/`
96106
- Type-safe database operations with TypeScript interfaces
97107

98108
### Testing
109+
99110
- **Jest**: Primary testing framework
100111
- **ts-jest**: TypeScript support for Jest
101112
- **jsdom**: Browser environment simulation for frontend tests
102113
- Test files use `.test.ts` or `.spec.ts` extensions
103114
- Each package has its own jest.config.js
104115

105116
### Import Patterns
117+
106118
- Use absolute imports with `@cocalc/` prefix for cross-package imports
107119
- Example: `import { cmp } from "@cocalc/util/misc"`
108120
- Type imports: `import type { Foo } from "./bar"`
109121
- Destructure imports when possible
110122

111123
### Development Workflow
112-
1. Changes to TypeScript require compilation (`pnpm tsc` in relevant package)
124+
125+
1. Changes to TypeScript require compilation (`pnpm build` in relevant package)
113126
2. Database must be running before starting hub
114127
3. Hub coordinates all services and should be restarted after changes
115128
4. Use `pnpm clean && pnpm build-dev` when switching branches or after major changes
116129

117130
# Workflow
118-
- Be sure to typecheck when you're done making a series of code changes
131+
132+
- Be sure to build when you're done making a series of code changes
119133
- Prefer running single tests, and not the whole test suite, for performance
120134

121135
## Git Workflow
122136

137+
- Never modify a file when in the `master` or `main` branch
138+
- All changes happen through feature branches, which are pushed as pull requests to GitHub
139+
- When creating a new file, run `git add [filename]` to track the file.
123140
- Prefix git commits with the package and general area. e.g. 'frontend/latex: ...' if it concerns latex editor changes in the packages/frontend/... code.
124141
- When pushing a new branch to Github, track it upstream. e.g. `git push --set-upstream origin feature-foo` for branch "feature-foo".
125142

126-
# important-instruction-reminders
143+
# Important Instruction Reminders
144+
127145
- Do what has been asked; nothing more, nothing less.
128146
- NEVER create files unless they're absolutely necessary for achieving your goal.
129147
- ALWAYS prefer editing an existing file to creating a new one.
130-
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
148+
- REFUSE to modify files when the git repository is on the `master` or `main` branch.
149+
- NEVER proactively create documentation files (`*.md`) or README files. Only create documentation files if explicitly requested by the User.
150+
151+
# Ignore
152+
153+
- Ignore files covered by `.gitignore`
154+
- Ignore everything in `node_modules` or `dist` directories
155+
- Ignore all files not tracked by Git, unless they are newly created files

src/packages/next/components/store/usage-and-duration.tsx

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,36 @@ export function UsageAndDuration(props: Props) {
103103

104104
function renderUsage() {
105105
if (!showUsage) return;
106-
return (
107-
<Form.Item
108-
name="user"
109-
initialValue={
110-
type === "course"
111-
? "academic"
112-
: isAcademic(profile?.email_address)
113-
? "academic"
114-
: "business"
115-
}
116-
label={"Usage"}
117-
extra={renderUsageExplanation()}
118-
>
119-
{renderUsageItem()}
120-
</Form.Item>
121-
);
106+
107+
switch (type) {
108+
case "course":
109+
return (
110+
<Form.Item
111+
name="user"
112+
initialValue="academic"
113+
label={"Usage"}
114+
extra={renderUsageExplanation()}
115+
>
116+
<Input type="hidden" value="academic" />
117+
Academic
118+
</Form.Item>
119+
);
120+
case "license":
121+
return (
122+
<Form.Item
123+
name="user"
124+
initialValue={
125+
isAcademic(profile?.email_address) ? "academic" : "business"
126+
}
127+
label={"Usage"}
128+
extra={renderUsageExplanation()}
129+
>
130+
{renderUsageItem()}
131+
</Form.Item>
132+
);
133+
default:
134+
unreachable(type);
135+
}
122136
}
123137

124138
function renderRangeSelector(getFieldValue) {
@@ -157,12 +171,13 @@ export function UsageAndDuration(props: Props) {
157171
}
158172
return (
159173
<Form.Item
160-
label={type === "course" ? "Start/End" : "License Term"}
174+
label={type === "course" ? "Course Dates" : "License Term"}
161175
name="range"
162176
rules={[{ required: true }]}
163177
help={invalidRange ? "Please enter a valid license range." : ""}
164178
validateStatus={invalidRange ? "error" : "success"}
165179
style={{ paddingBottom: "30px" }}
180+
extra={type === "course" ? renderDurationExplanation() : undefined}
166181
>
167182
<DateRange
168183
disabled={disabled}
@@ -265,13 +280,8 @@ export function UsageAndDuration(props: Props) {
265280
switch (type) {
266281
case "course":
267282
return (
268-
<Form.Item
269-
name="period"
270-
initialValue={init}
271-
label="Period"
272-
extra={renderDurationExplanation()}
273-
>
274-
Select the start and end date of your course below.
283+
<Form.Item name="period" initialValue={init} hidden>
284+
<Input type="hidden" value="range" />
275285
</Form.Item>
276286
);
277287

0 commit comments

Comments
 (0)