## Prompt for Developing Swap Time Logging Extension
Swap.work is a SaaS product catering to freelancers without company entities, enabling them to issue invoices. Currently, it lacks support for time tracking and using this for creating payment sheets. The goal is to implement time tracking functionality integrated directly into the existing Swap UI, enabling users to manage and export their time logs easily.
### Basic Info
- GraphQL base URL: `https://api.swap.work`
- JWT token is stored in `localStorage` under the key `account`.
- Use the POST method to interact with the GraphQL API.
- This should be implemented as a Greasemonkey script.
### Time Tracking Implementation
1. **Data Storage**:
- Use the project "comment" field for storing raw time tracking data.
2. **User Interface**:
- Implement a UI for recording, managing, and tracking time.
- Allow users to set their preference for the cost per hour.
- The UI should be a right sidebar panel on the desktop version.
- Utilize MUI class names to ensure the new UI blends seamlessly with the existing Swap UI.
3. **Time Entry Management**:
- CRUD capabilities (Create, Read, Update, Delete) for time tracking records.
- Manual time tracking entries allowed with custom cost settings.
4. **Cost Calculation and Export**:
- Use time tracking data to update cost entries.
- Export costs including time spent, detailed description, and calculated money.
- Use a specific format for cost entry titles: `[TT] (${duration}h) - ${description}`.
- Ensure existing cost data not managed by the program is not overwritten.
5. **API Interaction**:
- Fetch existing project data and income/cost details.
- Update project comments with time tracking data.
- Create, update, and delete costs based on time tracking data.
### Sample API Queries and Mutations
#### Get Projects
```graphql
query($offset: Int, $limit: Int, $orderBy: OrderBy, $filter: GetProjectsFromSOHOFilter) {
getProjectsFromSOHO(offset: $offset, limit: $limit, orderBy: $orderBy, filter: $filter) {
payload {
id
title
status
comment
c_company_name
created_at
started_at
completed_at
}
analysis {
totalIncomes
totalCosts
}
pagination {
count
limit
offset
}
status
message
errors
}
}
```
#### Update Project
```graphql
mutation($inputData: UpdateProjectFromSOHOInputData) {
updateProjectFromSOHO(inputData: $inputData) {
status
message
errors
}
}
```
#### Get Project Incomes and Costs
```graphql
query {
getProjectIncomesAndCostsFromSOHO(inputData: { project_id: "project_id" }) {
payload {
costs {
id
content
value
}
incomes {
id
content
value
}
extraCosts {
id
content
value
}
extraIncomes {
id
content
value
}
}
message
errors
}
}
```
#### Create Project Cost
```graphql
mutation {
createProjectCostFromSOHO(inputData: {
project_id: "project_id"
content: "Unnamed Cost"
value: 0
}) {
message
errors
}
}
```
#### Update Project Cost
```graphql
mutation {
updateProjectCostFromSOHO(inputData: {
project_id: "project_id"
id: 705
content: "Updated Content"
value: 0
}) {
message
errors
}
}
```
#### Delete Project Cost
```graphql
mutation {
deleteProjectCostFromSOHO(inputData: {
project_id: "project_id"
id: 704
}) {
message
errors
}
}
```
### Implementation Details
- Implement the Greasemonkey script to enhance the Swap.work interface.
- Integrate a right sidebar panel for time tracking, accessible only on the desktop.
- Ensure the feature integrates seamlessly with the Swap UI using MUI styles.
- Use GraphQL queries and mutations to interact with the backend, as specified.
### Note
- Do not overwrite existing cost data that aren't managed by the program.
- The script must function exclusively on the desktop, omitting mobile-specific designs.
By following these guidelines, you will augment the Swap.work interface with robust time tracking capabilities, enhancing productivity and invoice accuracy for freelancers.