Skip to content

Commit

Permalink
Update admin merchant / service teams compoments
Browse files Browse the repository at this point in the history
  • Loading branch information
ok200manami committed Aug 19, 2024
1 parent 39d13dd commit aea7fcc
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,27 @@ public function store(): JsonResponse

try {

$model = new TeamServiceTeam();

foreach ($validationArray as $key => $validationRule) {
$value = $this->request->get($key);
if ((isset($value))) {
$model->$key = $value;
$model = TeamServiceTeam::where('team_id', $this->request->get('team_id'))
->where('service_team_id', $this->request->get('service_team_id'))
->first();

if (!$model) {
$model = new TeamServiceTeam();

foreach ($validationArray as $key => $validationRule) {
$value = $this->request->get($key);
if ((isset($value))) {
$model->$key = $value;
}
}
}

$model->save();
$model->save();

}

$this->message = ApiResponse::RESPONSE_SAVED->value;
$this->data = $model;

$this->data = $model;

}
catch (Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ApiAdminTeamsController extends Controller
*/
public array $availableRelations = [
'teamsThisTeamIsMerchantFor',
'teamsThisTeamIsServiceFor',
];

public static array $searchableFields = [
Expand Down
10 changes: 10 additions & 0 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ public function teamsThisTeamIsMerchantFor(): HasMany
{
return $this->hasMany(TeamMerchantTeam::class, 'merchant_team_id', 'id');
}

public function teamServiceTeams(): HasMany
{
return $this->hasMany(TeamServiceTeam::class, 'team_id', 'id');
}

public function teamsThisTeamIsServiceFor(): HasMany
{
return $this->hasMany(TeamServiceTeam::class, 'service_team_id', 'id');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {Link} from '@inertiajs/vue3';
import AdminTeamDetailsComponent from "@/Components/Admin/AdminTeamDetailsComponent.vue";
import PrimaryButton from "@/Components/PrimaryButton.vue";
import Swal from "sweetalert2";
import AdminTeamSelectComponent from "@/Components/Admin/AdminTeamSelectComponent.vue";
import PaginatorComponent from "@/Components/Admin/PaginatorComponent.vue";
import AdminTeamMerchantTeamSelectComponent
from "@/Components/Admin/TeamMerchantTeams/AdminTeamMerchantTeamSelectComponent.vue";
Expand Down Expand Up @@ -103,7 +102,6 @@ function teamSelected(team) {

<div v-if="addingNewMerchant">
<div class="py-2">Select merchant team...</div>
<!-- <AdminTeamSelectComponent :excludeTeams="merchants" :teamId="teamId" @teamSelected="teamSelected"/>-->
<AdminTeamMerchantTeamSelectComponent :teamId="teamId" @teamSelected="teamSelected"></AdminTeamMerchantTeamSelectComponent>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {Link} from '@inertiajs/vue3';
import AdminTeamDetailsComponent from "@/Components/Admin/AdminTeamDetailsComponent.vue";
import PrimaryButton from "@/Components/PrimaryButton.vue";
import Swal from "sweetalert2";
import AdminTeamSelectComponent from "@/Components/Admin/AdminTeamSelectComponent.vue";
import PaginatorComponent from "@/Components/Admin/PaginatorComponent.vue";
import AdminTeamServiceTeamSelectComponent
from "@/Components/Admin/TeamServiceTeams/AdminTeamServiceTeamSelectComponent.vue";
const $props = defineProps({
teamId: {
Expand Down Expand Up @@ -101,7 +102,7 @@ function teamSelected(team) {

<div v-if="addingNewService">
<div class="py-2">Select service team...</div>
<AdminTeamSelectComponent :excludeTeams="services" :teamId="teamId" @teamSelected="teamSelected"/>
<AdminTeamServiceTeamSelectComponent :teamId="teamId" @teamSelected="teamSelected"></AdminTeamServiceTeamSelectComponent>
</div>

<div v-else-if="creatingNewTeamService">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import {onMounted, ref} from "vue";
import {ref} from "vue";
import TextInput from "@/Components/TextInput.vue";
import InputLabel from "@/Components/InputLabel.vue";
import AdminTeamDetailsComponent from "@/Components/Admin/AdminTeamDetailsComponent.vue";
Expand All @@ -14,7 +14,6 @@ const $props = defineProps({
})
const creatingANewTeam = ref(false)
const searchStr = ref('')
const teams = ref({})
Expand All @@ -23,11 +22,6 @@ const emit = defineEmits([
]
);
onMounted(() => {
})
function searchTeam() {
axios.get('/admin/teams?where[]=name,like,*' + searchStr.value + '*&limit=100&relations=teamsThisTeamIsMerchantFor').then(response => {
teams.value = response.data.data;
Expand Down Expand Up @@ -84,7 +78,6 @@ function myTeamIsATeamMerchant(anotherTeam){
<button @click="teamSelected(team)" class="flex justify-start items-end">
<AdminTeamDetailsComponent :team="team"/>
<span v-if="myTeamIsATeamMerchant(team)" class="text-red-500 text-xs italic pl-2">***Already added</span>
<span v-if="team.id === $props.teamId" class="text-red-500 text-xs italic pl-2">***Own team cannot be added</span>
</button>
</div>
<div class="text-red-500 text-sm mt-4 cursor-pointer hover:underline" @click="startCreatingNewTeam()">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
<script setup>
import {onMounted, ref} from "vue";
import {ref} from "vue";
import TextInput from "@/Components/TextInput.vue";
import InputLabel from "@/Components/InputLabel.vue";
import AdminTeamDetailsComponent from "@/Components/Admin/AdminTeamDetailsComponent.vue";
import AdminTeamCreateComponent from "@/Components/Admin/AdminTeamCreateComponent.vue";
const $props = defineProps({
excludeTeams: {
required: false,
default: {}
},
teamId: {
required: false,
default: null
}
})
const creatingANewTeam = ref(false)
const excludeTeamIdsArray = ref([])
const searchStr = ref('')
const teams = ref({})
Expand All @@ -26,31 +22,17 @@ const emit = defineEmits([
]
);
onMounted(() => {
createExcludeTeamIdsArray()
})
function createExcludeTeamIdsArray() {
if ($props.excludeTeams.data && $props.excludeTeams.data.length > 0) {
$props.excludeTeams.data.forEach((team) => {
if (team.service_team_id) {
excludeTeamIdsArray.value.push(team.service_team_id)
}
if (team.merchant_team_id) {
excludeTeamIdsArray.value.push(team.merchant_team_id)
}
})
}
}
function searchTeam() {
axios.get('/admin/teams?where[]=name,like,*' + searchStr.value + '*&limit=100').then(response => {
teams.value = response.data.data
axios.get('/admin/teams?where[]=name,like,*' + searchStr.value + '*&limit=100&relations=teamsThisTeamIsServiceFor').then(response => {
teams.value = response.data.data;
}).catch(error => {
console.log(error)
})
});
}
function startCreatingNewTeam() {
creatingANewTeam.value = true
teams.value = {}
Expand All @@ -66,6 +48,12 @@ function teamSelected(team) {
teams.value = {}
}
function myTeamIsATeamService(anotherTeam){
return anotherTeam.teams_this_team_is_service_for.find(subTeam => {
return subTeam.team_id === $props.teamId;
});
}
</script>

<template>
Expand All @@ -87,13 +75,9 @@ function teamSelected(team) {

<div v-if="searchStr.length > 0 && teams.total > 0" class="mt-4">
<div v-for="team in teams.data" class="border-b py-1">
<button @click="teamSelected(team)" class="flex justify-start items-end"
:class="{'text-gray-500 cursor-not-allowed': (excludeTeamIdsArray.includes(team.id) || team.id === $props.teamId),
'cursor-pointer': (!excludeTeamIdsArray.includes(team.id) && team.id !== $props.teamId)}"
:disabled="(excludeTeamIdsArray.includes(team.id) || team.id === $props.teamId)">
<button @click="teamSelected(team)" class="flex justify-start items-end">
<AdminTeamDetailsComponent :team="team"/>
<span v-if="excludeTeamIdsArray.includes(team.id)" class="text-red-500 text-xs italic pl-2">***Already added</span>
<span v-if="team.id === $props.teamId" class="text-red-500 text-xs italic pl-2">***Own team cannot be added</span>
<span v-if="myTeamIsATeamService(team)" class="text-red-500 text-xs italic pl-2">***Already added</span>
</button>
</div>
<div class="text-red-500 text-sm mt-4 cursor-pointer hover:underline" @click="startCreatingNewTeam()">
Expand All @@ -107,4 +91,5 @@ function teamSelected(team) {
</div>
</div>
</div>

</template>

0 comments on commit aea7fcc

Please sign in to comment.