hackforla / hackforla/HomeUniteUs

Dev: Display Host Contact Information Form Progress

Open
#716 3 comments 0 reactions 1 assignee Claimed by @mugdhchauhan View on GitHub
Complexity: Medium discussion Feature: Architecture Ready for: Dev Team Member Role: Back End Role: Front End size: 2pt
Dominant language
Python
Stars
45
Forks
22
Avg merge
15d 1h
Merged PRs (30d)
1

Description

## 🧩 Overview

This issue focuses on **showing dynamic status icons (βœ“βƒ complete, ◐ partial, β—― incomplete)** to indicate the completion state of the Contact Info section in the Host Profile. The backend evaluates the user's submitted data and returns a status that the frontend uses to render the correct icon.

---

## More Info

This form is part of the Host Profile intake. Users can select a preferred contact method (`"Email"` or `"Text"`) and optionally fill out a phone number.

**The UI displays a status icon based on backend logic:**

* βœ“βƒ **Complete**: All required fields are valid based on context (e.g., email chosen, phone not needed)
* ◐ **Partial**: At least one field is filled, but not enough to count as complete
* β—― **Incomplete**: No relevant data provided

*Example:* If the user chooses `"Email"` as their preferred method but does **not** provide a phone number, the status should still show βœ“βƒ because phone is not required in that context.

---

## πŸ“ Scope of Work

* Make `phone_number` optional in schema and DB
* Evaluate contact info completion **based on conditional rules**
* Return correct status (`complete`, `partial`, or `incomplete`)
* **Status should drive icon logic** on the frontend
* Prevent duplicate `contact_info` entries (update existing if same `user_id`)

---

## πŸ”§ Engineering Tasks

**Steps to Implement:**

* [x] Make `phone_number` optional in `ContactInfoCreate` schema
* [x] Update Alembic migration to make `phone_number` nullable in DB
* [x] Modify `crud.py` to update existing contact info
* [x] Update `determine_status()` in `routes.py`:

* βœ“βƒ If `preferred_method == "Email"` β†’ `phone_number` not required for **complete**
* βœ“βƒ If `preferred_method == "Text"` β†’ `phone_number` **is** required for **complete**
* ◐ One of the fields present but not enough to meet full rules β†’ **partial**
* β—― Neither field provided β†’ **incomplete**

---

## βœ… Acceptance Criteria

* [x] Submitting contact info with only email (preferred\_method=email) is valid
* [x] Submitting contact info with phone (preferred\_method=phone) requires phone\_number with 10+ digits
* [x] Backend replaces existing entry if user already has a contact\_info row
* [x] Backend `/completion-status` returns correct status based on inputs
* [x] Frontend shows βœ“βƒ if contact info is "complete", ◐ if partial, β—― if incomplete
* [x] Status icons are clearly visible and emphasized in UI

---

## πŸ”„ Dependencies

* Frontend must implement logic to map `completion-status` to appropriate status icons

---

## πŸ“¦ Technical Notes

* Backend: FastAPI, SQLAlchemy, Pydantic
* Used `Optional[str]` for `phone_number` in Pydantic schema
* Status is computed dynamically using `determine_status()` in route
* Backend logic ensures only one row per user in `contact_info` table
* Frontend updates icon based on backend status: βœ“βƒ / ◐ / β—―
* POST `/contact-info` acts as upsert
* GET `/completion-status/{user_id}` returns `{ "Contact Information": "complete" | "partial" | "incomplete" }`

## πŸ§ͺ Testing Strategy

All validation can be covered by **manual testing**:

* βœ… Submit form with:

* Preferred method: **email** only β†’ **βœ“βƒ complete**
* Preferred method: **phone** + valid number β†’ **βœ“βƒ complete**
* Preferred method: **phone** + short/invalid number β†’ **◐ partial**
* No input at all β†’ **β—― incomplete**
* βœ… Observe status icons update correctly in UI
* βœ… Reload form and ensure saved data is preserved
* βœ… Resubmit form to test replacement (edit + save again)
* βœ… Check backend DB only contains **one row per user**

---

## 🚩 Risks / Considerations

* Risk: If backend logic doesn't perfectly match frontend icon mapping, users could be misled
* Consideration: Validation rules must remain synchronized between frontend and backend

---

## 🧡 Related Issues

- #720
- #919

---

## Action Items

- [X] Update issue with current Engineering Issue Template format
- [X] Come up with a solution
- [ ] Discuss with Dev Lead & Dev PM
- [ ] Share proposal with Product and Design

---

## πŸ“Ž Resources

* [Figma UI Reference](https://www.figma.com/design/BNWqZk8SHKbtN1nw8BB7VM/HUU-Main-File---11-2024?node-id=2353-17357&p=f&t=Oc38Ztov7RzUJWM0-0)
* [Intake Form data model](https://github.com/hackforla/HomeUniteUs/pull/672)
* [Form API](https://github.com/hackforla/HomeUniteUs/issues/636)

---

## Attachments/Screenshots (If Applicable):
- N/A

---

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.