Modifying Status

Now that customers can create and view ice cream orders, let's add functionality for shop staff to manage the order lifecycle. In a real ice cream shop, orders need to progress through different stages: from "active" (newly placed) to "processing" (being prepared) to "served" (completed) or "canceled" if needed.
Think of status modification like the workflow in a real ice cream shop. When a customer places an order, it starts as "active" - like a ticket on the order board. Then staff begins preparation ("processing"), and finally serves it to the customer ("served"). This tutorial shows you how to implement this natural workflow with proper validation and user-friendly controls.
Before implementing the functionality, let's understand the business logic behind ice cream order status transitions:
🟢Active → Processing
When a customer places an order, it starts as "active". Staff can begin processing it by clicking "Process".
🔵Processing → Served
While an order is being prepared, it's in "processing" status. Once ready, staff can mark it as "served".
Active → Canceled
Only active orders can be canceled. Once processing begins, cancellation is no longer allowed.
⚠️Business Rules
  • Only active orders can be processed or canceled
  • Only processing orders can be served
  • Served and canceled orders are final states

Implement Document Business Logic

Just like a real ice cream shop has rules about when orders can be processed or canceled, we need to implement these business rules in our code. The document layer is where we define these rules - think of it as the "shop policies" that ensure orders are handled correctly no matter who is working or how busy it gets.
apps/koyo/lib/icecreamOrder/icecreamOrder.document.ts
These methods implement our business rules directly in the data model:
🔄
process(): Checks if status is 'active' before changing to 'processing'
serve(): Validates that status is 'processing' before marking as 'served'
cancel(): Ensures only 'active' orders can be canceled
When validation fails, we throw a Revert with a dictionary key for user-friendly error messages. Let's add these error messages to our dictionary:
apps/koyo/lib/icecreamOrder/icecreamOrder.dictionary.ts

Implement Service Layer

Now we need service methods that act like the shop manager - coordinating between the business rules (document layer) and the actual data storage (database). When a staff member wants to process an order, the service layer fetches the order, applies the business rules, and saves the changes safely.
apps/koyo/lib/icecreamOrder/icecreamOrder.service.ts
Each service method follows the same pattern:
1️⃣
Fetch: Retrieve the order from database using getIcecreamOrder()
2️⃣
Execute: Call the business logic method (process(), serve(), or cancel())
3️⃣
Save: Persist the changes to database with save()
This pattern ensures that business rules are enforced at the document level while the service handles database transactions safely.

Create Signal Endpoints

Think of signal endpoints as the communication system between the frontend (like the shop's order display screen) and the backend (the kitchen and management system). When staff clicks a "Process" button on the screen, it needs to communicate with the backend to actually update the order. Akan.js automatically creates both REST and GraphQL versions of these endpoints, so different parts of your system can communicate however they prefer.
apps/koyo/lib/icecreamOrder/icecreamOrder.signal.ts
Each signal endpoint is decorated with @Mutation.Public() and takes the order ID as a parameter. The resolve() function ensures the returned data is properly formatted for both API formats.
We also need to add dictionary entries for these API endpoints so they display properly in the UI:
apps/koyo/lib/icecreamOrder/icecreamOrder.dictionary.ts

Create Frontend Store Actions

The store layer is like the control panel that staff actually interact with. It takes the complex API communications and turns them into simple actions like "processOrder()" that components can easily use. When a button is clicked, the store handles calling the API and updating the display automatically - just like how pressing a button on a shop's POS system updates both the backend and the screen.
apps/koyo/lib/icecreamOrder/icecreamOrder.store.ts
Each store action follows this pattern:
📡
API Call: Make an API request to signal endpoints through fetch methods
🔄
State Update: Update the local store state with the new order data using setIcecreamOrder()
This ensures that when status changes happen, the UI automatically reflects the updated state without requiring a page refresh.

Create Utility Components

Just like a real ice cream shop might have labeled buttons or stamps for different order stages, we'll create reusable button components for each action. These "digital buttons" can be placed anywhere in our interface - on order cards, in detailed views, or on staff dashboards. By creating them once as utility components, we ensure consistent behavior and styling throughout the entire application.
apps/koyo/lib/icecreamOrder/IcecreamOrder.Util.tsx
Each button component includes:
🎨Consistent Styling
Each button has appropriate styling: primary for Process, secondary for Serve, outlined warning for Cancel
🔒Disabled State
Buttons can be disabled when actions aren't allowed based on current status
🌍Internationalization
Button labels come from dictionary entries for proper multilingual support

Apply To Unit & View Components

Now comes the exciting part - putting all the pieces together! Just like adding action buttons to the order tickets in a real shop, we'll integrate our status management buttons directly into the order cards and detailed views. This means staff won't need to navigate to separate pages or menus - they can process orders right from wherever they're viewing them, making the workflow fast and intuitive.
Let's update the Unit component to include status management buttons:
apps/koyo/lib/icecreamOrder/IcecreamOrder.Unit.tsx
Now let's also add the buttons to the detailed view modal:
apps/koyo/lib/icecreamOrder/IcecreamOrder.View.tsx
Key features of this implementation:
Smart Disabling: Buttons are disabled when actions aren't allowed based on current status
📱
Responsive Layout: Buttons wrap gracefully on smaller screens with flex-wrap
🎨
Visual Hierarchy: Different button styles indicate action priority and type

Test Status Management

Let's test our status management implementation to ensure everything works correctly:
Testing Steps:
  1. Navigate to http://localhost:4201/icecreamOrder
  2. Create a new ice cream order (it will start as 'active')
  3. Notice that only 'Process' and 'Cancel' buttons are enabled
  4. Click 'Process' - the status should change to 'processing'
  5. Now only the 'Serve' button should be enabled
  6. Click 'Serve' - the status should change to 'served'
  7. All action buttons should now be disabled (final state)
Expected Behavior:
  • Status changes should be instant and visible
  • Button states should update automatically
  • Invalid actions should be prevented
  • Error messages should appear if business rules are violated

Status Management Best Practices

Here are important best practices for implementing status management in Akan.js:
🛡️Enforce Business Rules
Always validate state transitions at the document level using business methods. This ensures data integrity regardless of how the API is called.
💡Smart UI Controls
Disable buttons and hide actions that aren't valid for the current state. This provides immediate feedback to users about what actions are possible.
🔄Consistent Patterns
Follow the same pattern across all status operations: Document → Service → Signal → Store → Component. This makes your code predictable and maintainable.
📝Proper Error Handling
Use dictionary-based error messages with Revert exceptions. This ensures error messages are properly translated and user-friendly.

What's Next?

Excellent work! You've successfully implemented a complete status management system for your ice cream orders. Shop staff can now efficiently manage the order lifecycle with proper business rule enforcement.
🎉 What You've Accomplished:
  • Implemented business logic with validation
  • Created service layer for status operations
  • Built signal endpoints for status changes
  • Added frontend store actions
  • Created reusable utility components
  • Integrated smart UI controls
In the next tutorial, we'll learn how to edit existing data by implementing order modification functionality. This will allow customers to update their ice cream orders before they're processed, completing the full CRUD operations for our ice cream shop.
Released under the MIT License
Official Akan.js Consulting onAkansoft
Copyright © 2025 Akan.js. All rights reserved.
System managed bybassman