chore: 2-way binding for address forms, like this?

follow up to 1f0c9e2
This commit is contained in:
Livio Bieri 2023-11-14 20:31:07 +01:00 committed by Christian Cueni
parent b4524fdd77
commit 9d806e6ede
5 changed files with 28 additions and 22 deletions

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { ref, watch, watchEffect } from "vue";
const props = defineProps<{
modelValue: {
@ -22,6 +22,11 @@ watch(
},
{ deep: true }
);
// Synchronize external changes to the internal state
watchEffect(() => {
Object.assign(orgAddress.value, props.modelValue);
});
</script>
<template>

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { ref, watch, watchEffect } from "vue";
const props = defineProps<{
modelValue: {
@ -24,6 +24,11 @@ watch(
},
{ deep: true }
);
// Synchronize external changes to the internal state
watchEffect(() => {
Object.assign(address.value, props.modelValue);
});
</script>
<template>

View File

@ -49,9 +49,6 @@ const billingAddressData: Ref<BillingAddressType | null> = fetchBillingAddress.d
watch(billingAddressData, (newVal) => {
if (newVal) {
console.log("New billing address data: ", newVal);
// TODO: we get the billing address from the shop api but updating the form does not work
// TODO: I don't understand how this was supposed to work in the first place -> how do we do this? :)
address.value = {
firstName: newVal.first_name,
lastName: newVal.last_name,

View File

@ -10,9 +10,6 @@ from django.views import defaults as default_views
from django.views.decorators.csrf import csrf_exempt
from django_ratelimit.exceptions import Ratelimited
from graphene_django.views import GraphQLView
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
from vbv_lernwelt.api.user import list_organisations, me_user_view
from vbv_lernwelt.assignment.views import request_assignment_completion_status
@ -58,6 +55,9 @@ from vbv_lernwelt.importer.views import (
)
from vbv_lernwelt.notify.views import email_notification_settings
from vbv_lernwelt.shop.views import get_billing_address, update_billing_address
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
class SignedIntConverter(IntConverter):

View File

@ -4,30 +4,29 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('shop', '0001_initial'),
("shop", "0001_initial"),
]
operations = [
migrations.RenameField(
model_name='billingaddress',
old_name='company_street_address',
new_name='company_street',
model_name="billingaddress",
old_name="company_street_address",
new_name="company_street",
),
migrations.RenameField(
model_name='billingaddress',
old_name='company_street_number_address',
new_name='company_street_number',
model_name="billingaddress",
old_name="company_street_number_address",
new_name="company_street_number",
),
migrations.RenameField(
model_name='billingaddress',
old_name='street_address',
new_name='street',
model_name="billingaddress",
old_name="street_address",
new_name="street",
),
migrations.RenameField(
model_name='billingaddress',
old_name='street_number_address',
new_name='street_number',
model_name="billingaddress",
old_name="street_number_address",
new_name="street_number",
),
]