feat: enhance schedule publish account handling and caching mechanisms
This commit is contained in:
@@ -323,6 +323,12 @@ watch(
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
watch(
|
||||
schedulePublishAccounts,
|
||||
() => syncSchedulePublishAccountSelection(),
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
watch(currentBrandId, () => {
|
||||
form.promptRuleId = undefined
|
||||
})
|
||||
@@ -495,6 +501,7 @@ function hydrateForm(): void {
|
||||
normalizeClock(task.random_window_start, randomDefaultScheduleTime()))
|
||||
: randomDefaultScheduleTime()
|
||||
selectDefaultSubscriptionPrompt()
|
||||
syncSchedulePublishAccountSelection()
|
||||
}
|
||||
|
||||
function selectDefaultSubscriptionPrompt(): void {
|
||||
@@ -518,7 +525,9 @@ function buildSchedulePayload() {
|
||||
const coverMode = coverEnabled ? form.coverMode : 'specific'
|
||||
const coverAssetUrl = coverEnabled && coverMode === 'specific' ? form.coverAssetUrl.trim() : ''
|
||||
const publishAccountIds =
|
||||
form.autoPublish && form.publishTargetTab === 'media_accounts' ? form.publishAccountIds : []
|
||||
form.autoPublish && form.publishTargetTab === 'media_accounts'
|
||||
? currentSchedulePublishAccountIds()
|
||||
: []
|
||||
const publishEnterpriseSiteTargets =
|
||||
form.autoPublish && form.publishTargetTab === 'enterprise_sites'
|
||||
? buildScheduleEnterpriseSiteTargets()
|
||||
@@ -610,6 +619,25 @@ function canToggleSchedulePublishAccount(account: PublishAccountCard): boolean {
|
||||
return account.selectable || isSchedulePublishAccountSelected(account.id)
|
||||
}
|
||||
|
||||
function currentSchedulePublishAccountIds(): string[] {
|
||||
return filterExistingSchedulePublishAccountIds(form.publishAccountIds, schedulePublishAccounts.value)
|
||||
}
|
||||
|
||||
function syncSchedulePublishAccountSelection(): void {
|
||||
if (accountsQuery.isPending.value || accountsQuery.isFetching.value) {
|
||||
return
|
||||
}
|
||||
form.publishAccountIds = currentSchedulePublishAccountIds()
|
||||
}
|
||||
|
||||
function filterExistingSchedulePublishAccountIds(
|
||||
accountIds: string[],
|
||||
accounts: PublishAccountCard[],
|
||||
): string[] {
|
||||
const existingIds = new Set(accounts.map((account) => account.id))
|
||||
return accountIds.filter((id) => existingIds.has(id))
|
||||
}
|
||||
|
||||
function buildScheduleEnterpriseSiteTargets(): ScheduleEnterpriseSiteTarget[] {
|
||||
return form.publishEnterpriseSiteIds
|
||||
.map((siteId) => ({
|
||||
@@ -794,7 +822,7 @@ function validateForm(): boolean {
|
||||
}
|
||||
|
||||
if (isSchedule.value && form.autoPublish) {
|
||||
if (form.publishTargetTab === 'media_accounts' && form.publishAccountIds.length === 0) {
|
||||
if (form.publishTargetTab === 'media_accounts' && currentSchedulePublishAccountIds().length === 0) {
|
||||
message.warning(t('custom.messages.missingPublishTargets'))
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user