hcb icon indicating copy to clipboard operation
hcb copied to clipboard

Standardize model status fields

Open cjdenio opened this issue 2 years ago • 1 comments

The AchTransfer model has status, status_text, status_text_long, state, and state_icon, and they all return different things!

https://github.com/hackclub/hcb/blob/4236fc109e38ecd8a623bd51cc63bb5300fa3353/app/models/ach_transfer.rb#L161-L195

I propose that every stateful model should have:

  • state, which returns the raw, unformatted state as a symbol (e.g. :deposited)
  • state_color, which returns a CSS class for the color of the state badge (e.g. info)
  • state_icon, an optional icon to display alongside the badge
  • ---
  • An entry in config/locales/en.yml that contains humanized states, e.g.
states:
  ach_transfer:
    pending: "Pending approval"

cjdenio avatar Jan 10 '24 17:01 cjdenio

yes! I agree.

We should have a concern that:

  • Implements a default version of state, state_color, and state_icon that raise NotImplementedError.
  • If the concern detects that AASM is used, it can have a default implementation for state (aasm_state.to_sym)

As for I18n, I wonder if Rails expects it under a certain key

garyhtou avatar Jan 10 '24 19:01 garyhtou