Update contact info

This commit is contained in:
eraden 2022-07-16 19:00:16 +02:00
parent 80be8d2d88
commit eb945f5176
4 changed files with 27 additions and 10 deletions

View File

@ -63,6 +63,7 @@ customElements.define('contact-info-editor', class extends Component {
this.setAttribute('type', v); this.setAttribute('type', v);
const icon = this.shadowRoot.querySelector('contact-type-icon'); const icon = this.shadowRoot.querySelector('contact-type-icon');
icon.setAttribute('contact-type', v); icon.setAttribute('contact-type', v);
this.shadowRoot.querySelector('#contact_type').value = v;
this.shadowRoot.querySelector('#content').setAttribute('type', v === 'email' ? 'email' : 'text'); this.shadowRoot.querySelector('#content').setAttribute('type', v === 'email' ? 'email' : 'text');
} }
@ -93,6 +94,7 @@ customElements.define('contact-info-editor', class extends Component {
const input = form.querySelector('#contact-id'); const input = form.querySelector('#contact-id');
input && input.remove(); input && input.remove();
form.action = '/contacts/create'; form.action = '/contacts/create';
form.querySelector('input[type=submit]').value = 'Dodaj';
} }
#addId(v) { #addId(v) {
@ -104,5 +106,6 @@ customElements.define('contact-info-editor', class extends Component {
input.setAttribute('id', 'contact-id'); input.setAttribute('id', 'contact-id');
input.value = v; input.value = v;
form.action = '/contacts/update'; form.action = '/contacts/update';
form.querySelector('input[type=submit]').value = 'Zmień';
} }
}); });

View File

@ -33,6 +33,10 @@ customElements.define('contact-info',
this.shadowRoot.querySelector('contact-type-icon').setAttribute('contact-type', v); this.shadowRoot.querySelector('contact-type-icon').setAttribute('contact-type', v);
} }
get contact_type() {
return this.getAttribute('contact-type');
}
set content(v) { set content(v) {
this.setAttribute('content', v); this.setAttribute('content', v);
this.shadowRoot.querySelector('#content').textContent = v; this.shadowRoot.querySelector('#content').textContent = v;

View File

@ -12,8 +12,13 @@ customElements.define('edit-contact-info', class extends Component {
article { article {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
width: 100%;
} }
#actions { #actions {
display: flex;
justify-content: space-between;
}
#buttons {
display: flex; display: flex;
justify-content: start; justify-content: start;
} }
@ -23,8 +28,12 @@ customElements.define('edit-contact-info', class extends Component {
:host([mode = 'view']) contact-info-editor { :host([mode = 'view']) contact-info-editor {
display: none; display: none;
} }
:host([mode = 'edit']) #actions {
width: 100%;
}
:host([mode = 'edit']) contact-info-editor { :host([mode = 'edit']) contact-info-editor {
display: block; display: block;
min-width: 50%;
} }
:host([mode = 'view']) ::slotted(contact-info) { :host([mode = 'view']) ::slotted(contact-info) {
display: block; display: block;
@ -38,11 +47,13 @@ customElements.define('edit-contact-info', class extends Component {
<slot></slot> <slot></slot>
<section id="actions"> <section id="actions">
<contact-info-editor></contact-info-editor> <contact-info-editor></contact-info-editor>
<input type="button" value="Edytuj" id="edit" /> <div id="buttons">
<form action="/contacts/delete" method="post"> <input type="button" value="Edytuj" id="edit" />
<input type="hidden" name="id" id="remove-id" /> <form action="/contacts/delete" method="post">
<input type="submit" value="Usuń" id="remove" /> <input type="hidden" name="id" id="remove-id" />
</form> <input type="submit" value="Usuń" id="remove" />
</form>
</div>
</section> </section>
</article> </article>
`); `);
@ -56,8 +67,8 @@ customElements.define('edit-contact-info', class extends Component {
if (!info) return; if (!info) return;
form.contact_id = info.contact_id; form.contact_id = info.contact_id;
form.contact_type = info.contact_type; form.type = info.contact_type;
form.context = info.context; form.content = info.content;
this.mode = 'edit'; this.mode = 'edit';
}); });

View File

@ -853,11 +853,10 @@ pub async fn update_contact(
sqlx::query_as( sqlx::query_as(
r#" r#"
UPDATE contacts UPDATE contacts
VALUES SET
owner_id = $2,
contact_type = $3, contact_type = $3,
content = $4 content = $4
WHERE id = $1 WHERE id = $1 WHERE owner_id = $2
RETURNING RETURNING
id, id,
owner_id, owner_id,