mohd-faraz

_blogs

// blogs / 20260625.md

Dev Log: June 25 Wrap-up

2026-06-25
#refactoring#crm#frontend#typescript

Overview

Today was mostly about cleaning up some messy logic in the CRM service and making the UI configuration for our deals module actually make sense. It wasn’t exactly glamorous work, but the code feels a lot lighter now that I’ve stripped away some redundant checks.

What I Worked On

Simplifying User Checks

I spent a good chunk of the morning looking at our AccountService logic. We have this bit of code that runs after login to make sure specific user types (like partners or distributors) have their associated IDs cached. It was getting a bit out of hand with nested if/else blocks and redundant API calls.

I flattened the logic to bail out early if the user isn't one of the restricted types. It's much easier to read now. I also caught a bug where the app would occasionally hang during login if the userId was present but the session metadata hadn't fully propagated yet. Adding a few guard clauses fixed that right up.

// Simplified the logic to avoid deep nesting
performContextChecks(userId: string) {
  const userType = this.getCurrentUserType();
  const isSpecialAccount = ['partner', 'distributor'].includes(userType);

  if (!isSpecialAccount) return;

  const storageKey = userType === 'partner' ? 'p_id' : 'd_id';
  const cachedValue = localStorage.getItem(storageKey);

  if (!cachedValue && userId) {
    // Only fetch if we're missing the ID and have a valid user
    this.fetchAndCacheMetadata(userId, storageKey);
  } else if (!cachedValue) {
    // Safety net: if we have no ID and no user, kill the session
    this.forceLogout();
  }
}

Refining the Deals Module

I also spent some time diving into the JSON configurations for our Deals module. We had a field labeled “Subscription Type,” which sounds okay on paper but didn't really match how the users talk. I renamed it to “Plan” across the board—it’s punchier and more intuitive.

Beyond just renaming, I reorganized the layout. Before, everything was just in one long list of fields. I grouped the plan and product details into their own dedicated section called “Plan & Product” and enabled a few missing fields for distributors. It's a small change, but the UI looks significantly less cluttered now that related data is actually sitting together.

Wrapping Up

It feels good to get these smaller, annoying issues out of the way. When you're moving fast, it's easy to let if/else blocks pile up until they're a headache to maintain. Tomorrow, I'll probably shift my focus back to the reporting side of things, but for tonight, I'm just glad the login flow is a bit more robust.