Welcome to mirror list, hosted at ThFree Co, Russian Federation.

organization_form_wrapper.vue « components « organizations « crm « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01bff4b69d60a509b692df9ea1bfe1d2fc4cc783 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<script>
import { s__, __ } from '~/locale';
import { convertToGraphQLId } from '~/graphql_shared/utils';
import { TYPE_CRM_ORGANIZATION, TYPE_GROUP } from '~/graphql_shared/constants';
import CrmForm from '../../components/crm_form.vue';
import getGroupOrganizationsQuery from './graphql/get_group_organizations.query.graphql';
import createOrganizationMutation from './graphql/create_organization.mutation.graphql';
import updateOrganizationMutation from './graphql/update_organization.mutation.graphql';

export default {
  components: {
    CrmForm,
  },
  inject: ['groupFullPath', 'groupId'],
  props: {
    isEditMode: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  computed: {
    organizationGraphQLId() {
      if (!this.isEditMode) return null;

      return convertToGraphQLId(TYPE_CRM_ORGANIZATION, this.$route.params.id);
    },
    groupGraphQLId() {
      return convertToGraphQLId(TYPE_GROUP, this.groupId);
    },
    mutation() {
      if (this.isEditMode) return updateOrganizationMutation;

      return createOrganizationMutation;
    },
    getQuery() {
      return {
        query: getGroupOrganizationsQuery,
        variables: { groupFullPath: this.groupFullPath, ids: [this.organizationGraphQLId] },
      };
    },
    title() {
      if (this.isEditMode) return s__('Crm|Edit organization');

      return s__('Crm|New organization');
    },
    successMessage() {
      if (this.isEditMode) return s__('Crm|Organization has been updated.');

      return s__('Crm|Organization has been added.');
    },
    additionalCreateParams() {
      return { groupId: this.groupGraphQLId };
    },
    fields() {
      const fields = [
        { name: 'name', label: __('Name'), required: true },
        {
          name: 'defaultRate',
          label: s__('Crm|Default rate'),
          input: { type: 'number', step: '0.01' },
        },
        { name: 'description', label: __('Description') },
      ];

      if (this.isEditMode)
        fields.push({ name: 'active', label: s__('Crm|Active'), required: true, bool: true });

      return fields;
    },
  },
};
</script>

<template>
  <crm-form
    :drawer-open="true"
    :get-query="getQuery"
    get-query-node-path="group.organizations"
    :mutation="mutation"
    :additional-create-params="additionalCreateParams"
    :existing-id="organizationGraphQLId"
    :fields="fields"
    :title="title"
    :success-message="successMessage"
  />
</template>