mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
Merge branch 'refactor_community' into frontend_show_gradido_id
This commit is contained in:
commit
4af4ddcba5
@ -22,7 +22,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted, watch } from 'vue'
|
||||||
import { useQuery } from '@vue/apollo-composable'
|
import { useQuery } from '@vue/apollo-composable'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { reachableCommunities } from '@/graphql/communities.graphql'
|
import { reachableCommunities } from '@/graphql/communities.graphql'
|
||||||
@ -33,6 +33,10 @@ const props = defineProps({
|
|||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({}),
|
default: () => ({}),
|
||||||
},
|
},
|
||||||
|
communityIdentifier: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue', 'communitiesLoaded'])
|
const emit = defineEmits(['update:modelValue', 'communitiesLoaded'])
|
||||||
@ -57,7 +61,17 @@ onResult(({ data }) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const communityIdentifier = computed(() => route.params.communityIdentifier)
|
const communityIdentifier = computed(
|
||||||
|
() => route.params.communityIdentifier || props.communityIdentifier,
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => communityIdentifier.value,
|
||||||
|
() => {
|
||||||
|
// console.log('CommunitySwitch.communityIdentifier.value', value)
|
||||||
|
setDefaultCommunity()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
function updateCommunity(community) {
|
function updateCommunity(community) {
|
||||||
// console.log('CommunitySwitch.updateCommunity...community=', community)
|
// console.log('CommunitySwitch.updateCommunity...community=', community)
|
||||||
|
|||||||
@ -48,8 +48,9 @@
|
|||||||
<community-switch
|
<community-switch
|
||||||
:disabled="isBalanceEmpty"
|
:disabled="isBalanceEmpty"
|
||||||
:model-value="form.targetCommunity"
|
:model-value="form.targetCommunity"
|
||||||
|
:community-identifier="autoCommunityIdentifier"
|
||||||
@update:model-value="updateField($event, 'targetCommunity')"
|
@update:model-value="updateField($event, 'targetCommunity')"
|
||||||
@communitiesLoaded="setCommunities"
|
@communities-loaded="setCommunities"
|
||||||
/>
|
/>
|
||||||
</BCol>
|
</BCol>
|
||||||
</BRow>
|
</BRow>
|
||||||
@ -173,6 +174,7 @@ const entityDataToForm = computed(() => ({ ...props }))
|
|||||||
const form = reactive({ ...entityDataToForm.value })
|
const form = reactive({ ...entityDataToForm.value })
|
||||||
const disableSmartValidState = ref(false)
|
const disableSmartValidState = ref(false)
|
||||||
const communities = ref([])
|
const communities = ref([])
|
||||||
|
const autoCommunityIdentifier = ref('')
|
||||||
|
|
||||||
const emit = defineEmits(['set-transaction'])
|
const emit = defineEmits(['set-transaction'])
|
||||||
|
|
||||||
@ -220,6 +222,7 @@ const validationSchema = computed(() => {
|
|||||||
return object({
|
return object({
|
||||||
memo: memoSchema,
|
memo: memoSchema,
|
||||||
amount: amountSchema,
|
amount: amountSchema,
|
||||||
|
// todo: found a better way, because this validation test has side effects
|
||||||
identifier: identifierSchema.test(
|
identifier: identifierSchema.test(
|
||||||
'community-is-reachable',
|
'community-is-reachable',
|
||||||
'form.validation.identifier.communityIsReachable',
|
'form.validation.identifier.communityIsReachable',
|
||||||
@ -229,18 +232,13 @@ const validationSchema = computed(() => {
|
|||||||
if (parts.length !== 2) {
|
if (parts.length !== 2) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
const com = communities.value.find((community) => {
|
return communities.value.some((community) => {
|
||||||
return (
|
return (
|
||||||
community.uuid === parts[0] ||
|
community.uuid === parts[0] ||
|
||||||
community.name === parts[0] ||
|
community.name === parts[0] ||
|
||||||
community.url === parts[0]
|
community.url === parts[0]
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
if (com) {
|
|
||||||
form.targetCommunity = com
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
@ -286,6 +284,26 @@ watch(userError, (error) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// if identifier contain valid community identifier of a reachable community:
|
||||||
|
// set it as target community and change community-switch to show only current value, instead of select
|
||||||
|
watch(
|
||||||
|
() => form.identifier,
|
||||||
|
(value) => {
|
||||||
|
autoCommunityIdentifier.value = ''
|
||||||
|
const parts = value.split('/')
|
||||||
|
if (parts.length === 2) {
|
||||||
|
const com = communities.value.find(
|
||||||
|
(community) =>
|
||||||
|
community.uuid === parts[0] || community.name === parts[0] || community.url === parts[0],
|
||||||
|
)
|
||||||
|
if (com) {
|
||||||
|
form.targetCommunity = com
|
||||||
|
autoCommunityIdentifier.value = com.uuid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
function onSubmit() {
|
function onSubmit() {
|
||||||
const transformedForm = validationSchema.value.cast(form)
|
const transformedForm = validationSchema.value.cast(form)
|
||||||
const parts = transformedForm.identifier.split('/')
|
const parts = transformedForm.identifier.split('/')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user