summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/crm/organizations/components
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/crm/organizations/components')
-rw-r--r--app/assets/javascripts/crm/organizations/components/graphql/create_organization.mutation.graphql10
-rw-r--r--app/assets/javascripts/crm/organizations/components/graphql/crm_organization_fields.fragment.graphql7
-rw-r--r--app/assets/javascripts/crm/organizations/components/graphql/get_group_organizations.query.graphql13
-rw-r--r--app/assets/javascripts/crm/organizations/components/graphql/update_organization.mutation.graphql10
-rw-r--r--app/assets/javascripts/crm/organizations/components/organization_form_wrapper.vue80
-rw-r--r--app/assets/javascripts/crm/organizations/components/organizations_root.vue142
6 files changed, 262 insertions, 0 deletions
diff --git a/app/assets/javascripts/crm/organizations/components/graphql/create_organization.mutation.graphql b/app/assets/javascripts/crm/organizations/components/graphql/create_organization.mutation.graphql
new file mode 100644
index 00000000000..2cc7e53ee9b
--- /dev/null
+++ b/app/assets/javascripts/crm/organizations/components/graphql/create_organization.mutation.graphql
@@ -0,0 +1,10 @@
+#import "./crm_organization_fields.fragment.graphql"
+
+mutation createOrganization($input: CustomerRelationsOrganizationCreateInput!) {
+ customerRelationsOrganizationCreate(input: $input) {
+ organization {
+ ...OrganizationFragment
+ }
+ errors
+ }
+}
diff --git a/app/assets/javascripts/crm/organizations/components/graphql/crm_organization_fields.fragment.graphql b/app/assets/javascripts/crm/organizations/components/graphql/crm_organization_fields.fragment.graphql
new file mode 100644
index 00000000000..4adc5742d3a
--- /dev/null
+++ b/app/assets/javascripts/crm/organizations/components/graphql/crm_organization_fields.fragment.graphql
@@ -0,0 +1,7 @@
+fragment OrganizationFragment on CustomerRelationsOrganization {
+ __typename
+ id
+ name
+ defaultRate
+ description
+}
diff --git a/app/assets/javascripts/crm/organizations/components/graphql/get_group_organizations.query.graphql b/app/assets/javascripts/crm/organizations/components/graphql/get_group_organizations.query.graphql
new file mode 100644
index 00000000000..e8d8109431e
--- /dev/null
+++ b/app/assets/javascripts/crm/organizations/components/graphql/get_group_organizations.query.graphql
@@ -0,0 +1,13 @@
+#import "./crm_organization_fields.fragment.graphql"
+
+query organizations($groupFullPath: ID!) {
+ group(fullPath: $groupFullPath) {
+ __typename
+ id
+ organizations {
+ nodes {
+ ...OrganizationFragment
+ }
+ }
+ }
+}
diff --git a/app/assets/javascripts/crm/organizations/components/graphql/update_organization.mutation.graphql b/app/assets/javascripts/crm/organizations/components/graphql/update_organization.mutation.graphql
new file mode 100644
index 00000000000..a4c46d1f0fa
--- /dev/null
+++ b/app/assets/javascripts/crm/organizations/components/graphql/update_organization.mutation.graphql
@@ -0,0 +1,10 @@
+#import "./crm_organization_fields.fragment.graphql"
+
+mutation updateOrganization($input: CustomerRelationsOrganizationUpdateInput!) {
+ customerRelationsOrganizationUpdate(input: $input) {
+ organization {
+ ...OrganizationFragment
+ }
+ errors
+ }
+}
diff --git a/app/assets/javascripts/crm/organizations/components/organization_form_wrapper.vue b/app/assets/javascripts/crm/organizations/components/organization_form_wrapper.vue
new file mode 100644
index 00000000000..38468e1f4e4
--- /dev/null
+++ b/app/assets/javascripts/crm/organizations/components/organization_form_wrapper.vue
@@ -0,0 +1,80 @@
+<script>
+import { s__, __ } from '~/locale';
+import { convertToGraphQLId } from '~/graphql_shared/utils';
+import { TYPE_CRM_ORGANIZATION, TYPE_GROUP } from '~/graphql_shared/constants';
+import OrganizationForm from '../../components/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: {
+ OrganizationForm,
+ },
+ 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 },
+ };
+ },
+ 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: [
+ { name: 'name', label: __('Name'), required: true },
+ {
+ name: 'defaultRate',
+ label: s__('Crm|Default rate'),
+ input: { type: 'number', step: '0.01' },
+ },
+ { name: 'description', label: __('Description') },
+ ],
+};
+</script>
+
+<template>
+ <organization-form
+ :drawer-open="true"
+ :get-query="getQuery"
+ get-query-node-path="group.organizations"
+ :mutation="mutation"
+ :additional-create-params="additionalCreateParams"
+ :existing-id="organizationGraphQLId"
+ :fields="$options.fields"
+ :title="title"
+ :success-message="successMessage"
+ />
+</template>
diff --git a/app/assets/javascripts/crm/organizations/components/organizations_root.vue b/app/assets/javascripts/crm/organizations/components/organizations_root.vue
new file mode 100644
index 00000000000..522e29eb2af
--- /dev/null
+++ b/app/assets/javascripts/crm/organizations/components/organizations_root.vue
@@ -0,0 +1,142 @@
+<script>
+import { GlAlert, GlButton, GlLoadingIcon, GlTable, GlTooltipDirective } from '@gitlab/ui';
+import { parseBoolean } from '~/lib/utils/common_utils';
+import { s__, __ } from '~/locale';
+import { getIdFromGraphQLId } from '~/graphql_shared/utils';
+import { EDIT_ROUTE_NAME, NEW_ROUTE_NAME } from '../../constants';
+import getGroupOrganizationsQuery from './graphql/get_group_organizations.query.graphql';
+
+export default {
+ components: {
+ GlAlert,
+ GlButton,
+ GlLoadingIcon,
+ GlTable,
+ },
+ directives: {
+ GlTooltip: GlTooltipDirective,
+ },
+ inject: ['canAdminCrmOrganization', 'groupFullPath', 'groupIssuesPath'],
+ data() {
+ return {
+ organizations: [],
+ error: false,
+ };
+ },
+ apollo: {
+ organizations: {
+ query() {
+ return getGroupOrganizationsQuery;
+ },
+ variables() {
+ return {
+ groupFullPath: this.groupFullPath,
+ };
+ },
+ update(data) {
+ return this.extractOrganizations(data);
+ },
+ error() {
+ this.error = true;
+ },
+ },
+ },
+ computed: {
+ isLoading() {
+ return this.$apollo.queries.organizations.loading;
+ },
+ canAdmin() {
+ return parseBoolean(this.canAdminCrmOrganization);
+ },
+ },
+ methods: {
+ extractOrganizations(data) {
+ const organizations = data?.group?.organizations?.nodes || [];
+ return organizations.slice().sort((a, b) => a.name.localeCompare(b.name));
+ },
+ getIssuesPath(path, value) {
+ return `${path}?scope=all&state=opened&crm_organization_id=${value}`;
+ },
+ getEditRoute(id) {
+ return { name: this.$options.EDIT_ROUTE_NAME, params: { id } };
+ },
+ },
+ fields: [
+ { key: 'name', sortable: true },
+ { key: 'defaultRate', sortable: true },
+ { key: 'description', sortable: true },
+ {
+ key: 'id',
+ label: '',
+ formatter: (id) => {
+ return getIdFromGraphQLId(id);
+ },
+ },
+ ],
+ i18n: {
+ emptyText: s__('Crm|No organizations found'),
+ issuesButtonLabel: __('View issues'),
+ editButtonLabel: __('Edit'),
+ title: s__('Crm|Customer relations organizations'),
+ newOrganization: s__('Crm|New organization'),
+ errorText: __('Something went wrong. Please try again.'),
+ },
+ EDIT_ROUTE_NAME,
+ NEW_ROUTE_NAME,
+};
+</script>
+
+<template>
+ <div>
+ <gl-alert v-if="error" variant="danger" class="gl-mt-6" @dismiss="error = false">
+ {{ $options.i18n.errorText }}
+ </gl-alert>
+ <div
+ class="gl-display-flex gl-align-items-baseline gl-flex-direction-row gl-justify-content-space-between gl-mt-6"
+ >
+ <h2 class="gl-font-size-h2 gl-my-0">
+ {{ $options.i18n.title }}
+ </h2>
+ <div
+ v-if="canAdmin"
+ class="gl-display-none gl-md-display-flex gl-align-items-center gl-justify-content-end"
+ >
+ <router-link :to="{ name: $options.NEW_ROUTE_NAME }">
+ <gl-button variant="confirm" data-testid="new-organization-button">
+ {{ $options.i18n.newOrganization }}
+ </gl-button>
+ </router-link>
+ </div>
+ </div>
+ <router-view />
+ <gl-loading-icon v-if="isLoading" class="gl-mt-5" size="lg" />
+ <gl-table
+ v-else
+ class="gl-mt-5"
+ :items="organizations"
+ :fields="$options.fields"
+ :empty-text="$options.i18n.emptyText"
+ show-empty
+ >
+ <template #cell(id)="{ value: id }">
+ <gl-button
+ v-gl-tooltip.hover.bottom="$options.i18n.issuesButtonLabel"
+ class="gl-mr-3"
+ data-testid="issues-link"
+ icon="issues"
+ :aria-label="$options.i18n.issuesButtonLabel"
+ :href="getIssuesPath(groupIssuesPath, id)"
+ />
+ <router-link :to="getEditRoute(id)">
+ <gl-button
+ v-if="canAdmin"
+ v-gl-tooltip.hover.bottom="$options.i18n.editButtonLabel"
+ data-testid="edit-organization-button"
+ icon="pencil"
+ :aria-label="$options.i18n.editButtonLabel"
+ />
+ </router-link>
+ </template>
+ </gl-table>
+ </div>
+</template>