Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/TField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
:auto-focus="autoFocus"
:hide-label="hideLabel"
:item="item"
:error="error"
v-on="$attrs.listeners"
@input="(val) => $emit('input', set(val))"
/>
Expand Down Expand Up @@ -131,6 +132,10 @@ export default {
set: {
type: Function,
default: (val) => val
},
error: {
type: String,
default: ''
}
},
data: () => ({
Expand Down
26 changes: 22 additions & 4 deletions components/TForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:value="value ? value[field.name] : ''"
:item="value"
v-bind="field"
:error="usernameError"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a form components, username is not always one of the fields of the form

:label="getLabel(field)"
@input="(val) => onFieldChange(field, val)"
/>
Expand Down Expand Up @@ -32,9 +33,18 @@

<script>
import { camelcase } from '~/utils'
import { useDoc } from '~/use/doc'

export default {
name: 'TForm',
setup() {
const { find, id } = useDoc('profiles')

return {
find,
id
}
},
components: {
TField: () => import('~/components/TField')
},
Expand Down Expand Up @@ -77,7 +87,8 @@ export default {
}
},
data: () => ({
error: false
error: false,
usernameError: ''
}),
computed: {
visibleFields() {
Expand Down Expand Up @@ -136,18 +147,26 @@ export default {

this.$emit('copy', this.value)
},
save() {
async save() {
this.error = false

if (!this.validate()) {
return
}

await this.find('username', this.value.username)

if (this.id && this.id !== this.value.id) {
this.usernameError = 'This name is already taken'
this.$emit('input', this.value)
return
}

this.$emit('save', this.value)
},
onFieldChange(field, value) {
this.usernameError = ''
const val = { ...this.value }

if (value) {
this.$set(val, field.name, value)
} else {
Expand All @@ -157,7 +176,6 @@ export default {
if (field && field.onChange) {
field.onChange(val)
}

this.$emit('input', val)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably used somewhere, did you check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did and form seems to function the same without it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check commit where this line was added and see why

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems redundant since inline emit in another file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sets a new value for the form, whenever any field is changed. If this event is not emitted v-model of the form won't be updated.

}
}
Expand Down
29 changes: 6 additions & 23 deletions components/TInput/TInputUsername.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,8 @@
</template>

<script>
import { useDoc } from '~/use/doc'

export default {
name: 'TInputUsername',
setup() {
const { find, id } = useDoc('profiles')

return {
find,
id
}
},
inheritAttrs: false,
props: {
value: {
Expand All @@ -36,11 +26,14 @@ export default {
item: {
type: Object,
default: () => ({})
},
error: {
type: String,
default: ''
}
},
data: () => ({
computedValue: '',
error: ''
computedValue: ''
}),
watch: {
value(val) {
Expand All @@ -53,21 +46,11 @@ export default {
this.computedValue = this.value
},
methods: {
async save(newName) {
this.error = ''

save(newName) {
if (newName === this.value) {
return
}

await this.find('username', newName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can just put this code inside a new method validate and call this method on form save?


if (this.id && this.id !== this.item.id) {
this.error = 'This name is already taken'
this.$emit('input', this.value)
return
}

this.$emit('input', newName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/TPresentation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</div>
</TPopup>

<TPopup v-else-if="slide == 2" @close="close">
<TPopup v-else-if="slide === 2" @close="close">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is not part of this issue

<div class="p-4 text-center">
<TIcon class="w-64" name="undraw_work_chat" />
<div class="mt-8 w-64">
Expand Down