HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/node_modules/@vue/cli-ui/src/mixins/Prompts.js
import PROMPT_ANSWER from '@/graphql/prompt/promptAnswer.gql'

export default function ({
  field,
  query,
  variables = null,
  updateQuery = null,
  update = null
}) {
  // @vue/component
  return {
    computed: {
      configurationValid () {
        return this.visiblePrompts.filter(
          p =>
            p.error ||
            p.value === null ||
            JSON.parse(p.value) === ''
        ).length === 0
      },

      hasPromptsChanged () {
        return !!this.visiblePrompts.find(
          prompt => prompt.valueChanged
        )
      },

      visiblePrompts () {
        if (!this[field]) {
          return []
        }
        return this[field].prompts.filter(
          p => p.visible
        )
      }
    },

    watch: {
      hasPromptsChanged: {
        handler (value) {
          this.$emit('has-changes', value)
        },
        immediate: true
      }
    },

    methods: {
      async answerPrompt ({ prompt, value }) {
        await this.$apollo.mutate({
          mutation: PROMPT_ANSWER,
          variables: {
            input: {
              id: prompt.id,
              value: JSON.stringify(value)
            }
          },
          update: (store, { data: { promptAnswer } }) => {
            if (update) {
              update.call(this, store, promptAnswer)
              return
            }
            let vars = variables || this.$apollo.queries[field].options.variables || undefined
            if (typeof vars === 'function') {
              vars = vars.call(this)
            }
            const data = store.readQuery({ query, variables: vars })
            if (updateQuery) {
              updateQuery.call(this, data, promptAnswer)
            } else {
              data[field].prompts = promptAnswer
            }
            store.writeQuery({ query, variables: vars, data })
          }
        })
      }
    }
  }
}