forked from jsnbuchanan/crowd-funder-for-time-pwa
Refactor: simplify GiftedDialog with explicit entity type props
Replace complex updateEntityTypes() method with explicit giverEntityType and recipientEntityType props. This makes the component more declarative and maintainable by removing hidden logic and making entity type relationships clear at the call site. - Remove updateEntityTypes() method and related watchers - Add explicit giverEntityType and recipientEntityType props with defaults - Update all views to use inline logic for entity type determination - Fix entity type preservation in navigation flows - Enhance query parameter passing for better context preservation - Fix recipient reset issue in ContactGiftingView - Resolve entity type mismatch in HomeView project button flow Files changed: - GiftedDialog.vue: Remove complex logic, add explicit props - EntitySelectionStep.vue: Enhanced query parameter handling - ContactGiftingView.vue: Improved context preservation - HomeView.vue, ProjectViewView.vue, ClaimView.vue, ContactsView.vue: Updated to use explicit entity type props - Add refactoring documentation
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<div
|
||||
class="dialog"
|
||||
data-testid="gifted-dialog"
|
||||
:data-recipient-entity-type-override="recipientEntityTypeOverride"
|
||||
:data-recipient-entity-type="recipientEntityType"
|
||||
>
|
||||
<!-- Step 1: Entity Selection -->
|
||||
<EntitySelectionStep
|
||||
@@ -11,7 +11,9 @@
|
||||
:step-type="stepType"
|
||||
:giver-entity-type="giverEntityType"
|
||||
:recipient-entity-type="recipientEntityType"
|
||||
:show-projects="showProjects"
|
||||
:show-projects="
|
||||
giverEntityType === 'project' || recipientEntityType === 'project'
|
||||
"
|
||||
:is-from-project-view="isFromProjectView"
|
||||
:projects="projects"
|
||||
:all-contacts="allContacts"
|
||||
@@ -60,7 +62,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Vue, Component, Prop, Watch } from "vue-facing-decorator";
|
||||
import { Vue, Component, Prop } from "vue-facing-decorator";
|
||||
|
||||
import {
|
||||
createAndSubmitGive,
|
||||
@@ -105,29 +107,13 @@ export default class GiftedDialog extends Vue {
|
||||
|
||||
@Prop() fromProjectId = "";
|
||||
@Prop() toProjectId = "";
|
||||
@Prop({ default: false }) showProjects = false;
|
||||
@Prop() isFromProjectView = false;
|
||||
@Prop() recipientEntityTypeOverride?: "person" | "project";
|
||||
|
||||
@Watch("showProjects")
|
||||
onShowProjectsChange() {
|
||||
this.updateEntityTypes();
|
||||
}
|
||||
|
||||
@Watch("fromProjectId")
|
||||
onFromProjectIdChange() {
|
||||
this.updateEntityTypes();
|
||||
}
|
||||
|
||||
@Watch("toProjectId")
|
||||
onToProjectIdChange() {
|
||||
this.updateEntityTypes();
|
||||
}
|
||||
|
||||
@Watch("recipientEntityTypeOverride")
|
||||
onRecipientEntityTypeOverrideChange() {
|
||||
this.updateEntityTypes();
|
||||
}
|
||||
@Prop({ default: "person" }) giverEntityType = "person" as
|
||||
| "person"
|
||||
| "project";
|
||||
@Prop({ default: "person" }) recipientEntityType = "person" as
|
||||
| "person"
|
||||
| "project";
|
||||
|
||||
activeDid = "";
|
||||
allContacts: Array<Contact> = [];
|
||||
@@ -203,50 +189,6 @@ export default class GiftedDialog extends Vue {
|
||||
}
|
||||
|
||||
stepType = "giver";
|
||||
giverEntityType = "person" as "person" | "project";
|
||||
recipientEntityType = "person" as "person" | "project";
|
||||
|
||||
updateEntityTypes() {
|
||||
// Reset and set entity types based on current context
|
||||
this.giverEntityType = "person";
|
||||
this.recipientEntityType = "person";
|
||||
|
||||
// If recipient entity type is explicitly overridden, use that
|
||||
if (this.recipientEntityTypeOverride) {
|
||||
this.recipientEntityType = this.recipientEntityTypeOverride;
|
||||
}
|
||||
|
||||
// Determine entity types based on current context
|
||||
if (this.showProjects) {
|
||||
// HomeView "Project" button or ProjectViewView "Given by This"
|
||||
this.giverEntityType = "project";
|
||||
// Only override recipient if not already set by recipientEntityTypeOverride
|
||||
if (!this.recipientEntityTypeOverride) {
|
||||
this.recipientEntityType = "person";
|
||||
}
|
||||
} else if (this.fromProjectId) {
|
||||
// ProjectViewView "Given by This" button (project is giver)
|
||||
this.giverEntityType = "project";
|
||||
// Only override recipient if not already set by recipientEntityTypeOverride
|
||||
if (!this.recipientEntityTypeOverride) {
|
||||
this.recipientEntityType = "person";
|
||||
}
|
||||
} else if (this.toProjectId) {
|
||||
// ProjectViewView "Given to This" button (project is recipient)
|
||||
this.giverEntityType = "person";
|
||||
// Only override recipient if not already set by recipientEntityTypeOverride
|
||||
if (!this.recipientEntityTypeOverride) {
|
||||
this.recipientEntityType = "project";
|
||||
}
|
||||
} else {
|
||||
// HomeView "Person" button
|
||||
this.giverEntityType = "person";
|
||||
// Only override recipient if not already set by recipientEntityTypeOverride
|
||||
if (!this.recipientEntityTypeOverride) {
|
||||
this.recipientEntityType = "person";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async open(
|
||||
giver?: libsUtil.GiverReceiverInputInfo,
|
||||
@@ -261,7 +203,6 @@ export default class GiftedDialog extends Vue {
|
||||
this.giver = giver;
|
||||
this.receiver = receiver;
|
||||
this.offerId = offerId || "";
|
||||
console.log("offerId", this.offerId);
|
||||
this.prompt = prompt || "";
|
||||
this.description = description || "";
|
||||
this.amountInput = amountInput || "0";
|
||||
@@ -270,8 +211,7 @@ export default class GiftedDialog extends Vue {
|
||||
this.firstStep = !giver;
|
||||
this.stepType = "giver";
|
||||
|
||||
// Update entity types based on current props
|
||||
this.updateEntityTypes();
|
||||
// Entity types are now set via props, no need to call updateEntityTypes()
|
||||
|
||||
try {
|
||||
const settings = await this.$settings();
|
||||
|
||||
Reference in New Issue
Block a user