refactor: remove unused 'allMatches' state and related logic from CuttingVerifyDialog and StockVerifyDialog for cleaner code and improved maintainability

This commit is contained in:
Yoga Pangestu 2026-06-29 09:12:18 +07:00
parent 0fc6a9166a
commit e252f6c767
2 changed files with 2 additions and 78 deletions

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import { useForm } from '@inertiajs/vue3';
import { ref, watch } from 'vue';
import { watch } from 'vue';
import { toast } from 'vue-sonner';
import { RupiahInput } from '@/components/form/rupiah-input';
import { Badge } from '@/components/ui/badge';
@ -18,8 +18,6 @@ import {
FieldLabel,
} from '@/components/ui/field';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Switch } from '@/components/ui/switch';
import { Textarea } from '@/components/ui/textarea';
import { CuttingStatus } from '@/constants/cutting-status';
import { parseRupiah } from '@/lib/rupiah';
@ -36,8 +34,6 @@ const props = defineProps<{
const open = defineModel<boolean>('open', { required: true });
const allMatches = ref(true);
function buildEmptyPrices(): Record<string, string> {
return Object.fromEntries(PRICE_TYPES.map((type) => [type, '']));
}
@ -63,7 +59,6 @@ const verifyForm = useForm({
watch(open, (isOpen) => {
if (isOpen) {
allMatches.value = true;
verifyForm.verification_note = '';
verifyForm.results = props.cutting.results.map(res => ({
product_variant_id: res.product_variant?.id || 0,
@ -80,30 +75,6 @@ watch(open, (isOpen) => {
}
});
watch(allMatches, (matches) => {
if (!matches) {
return;
}
verifyForm.results = verifyForm.results.map((result) => ({
...result,
sample: result.original_sample,
original_outside_sample: result.original_original_outside_sample,
}));
});
function setAllMatches(value: boolean) {
allMatches.value = value;
if (value) {
verifyForm.results = verifyForm.results.map((result) => ({
...result,
sample: result.original_sample,
original_outside_sample: result.original_original_outside_sample,
}));
}
}
function setResultPrice(resultIndex: number, type: string, value: string) {
const result = verifyForm.results[resultIndex];
@ -166,13 +137,6 @@ function submitVerify() {
Verifikasi jumlah produk yang diterima di toko dan tentukan harga jual per varian.
</p>
<div class="flex items-center justify-between rounded-lg border p-3">
<Label for="all-matches" class="text-sm font-medium">
Semua sesuai dengan data cutting
</Label>
<Switch id="all-matches" :model-value="allMatches" @update:model-value="setAllMatches" />
</div>
<div class="space-y-3">
<div v-for="(result, index) in verifyForm.results" :key="result.product_variant_id"
class="p-3 border rounded-lg space-y-3">
@ -204,7 +168,6 @@ function submitVerify() {
(diterima):</label>
<Input :id="`sample-${index}`" type="number" v-model.number="result.sample" min="0"
:max="result.cutting_result" class="h-8 w-full px-2 text-xs"
:disabled="allMatches"
@input="result.original_outside_sample = result.cutting_result - result.sample" />
</div>
<div>
@ -215,7 +178,6 @@ function submitVerify() {
<Input :id="`diluar-sample-${index}`" type="number"
v-model.number="result.original_outside_sample" min="0"
:max="result.cutting_result" class="h-8 w-full px-2 text-xs"
:disabled="allMatches"
@input="result.sample = result.cutting_result - result.original_outside_sample" />
</div>
</div>

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import { useForm } from '@inertiajs/vue3';
import { computed, ref, watch } from 'vue';
import { computed, watch } from 'vue';
import { toast } from 'vue-sonner';
import { RupiahInput } from '@/components/form/rupiah-input';
import { Button } from '@/components/ui/button';
@ -17,9 +17,7 @@ import {
FieldLabel,
} from '@/components/ui/field';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Separator } from '@/components/ui/separator';
import { Switch } from '@/components/ui/switch';
import { Textarea } from '@/components/ui/textarea';
import { parseRupiah } from '@/lib/rupiah';
import { verify } from '@/routes/admin/manage/stocks';
@ -35,8 +33,6 @@ const props = defineProps<{
const open = defineModel<boolean>('open', { required: true });
const allMatches = ref(true);
function buildEmptyPrices(): Record<string, string> {
return Object.fromEntries(PRICE_TYPES.map((type) => [type, '']));
}
@ -64,7 +60,6 @@ const verifyForm = useForm({
watch(open, (isOpen) => {
if (isOpen) {
allMatches.value = true;
verifyForm.verification_note = '';
verifyForm.results = props.cutting.results.map(res => ({
product_variant_id: res.product_variant?.id || 0,
@ -85,30 +80,6 @@ watch(open, (isOpen) => {
}
});
watch(allMatches, (matches) => {
if (!matches) {
return;
}
verifyForm.results = verifyForm.results.map((result) => ({
...result,
good: result.cutting_result,
reject: 0,
}));
});
function setAllMatches(value: boolean) {
allMatches.value = value;
if (value) {
verifyForm.results = verifyForm.results.map((result) => ({
...result,
good: result.cutting_result,
reject: 0,
}));
}
}
function setSharedPrice(type: string, value: string) {
verifyForm.shared_prices[type] = value;
verifyForm.variant_prices = verifyForm.variant_prices.map((row) => ({
@ -172,13 +143,6 @@ function submitVerify() {
verifikasi.
</p>
<div class="flex items-center justify-between rounded-lg border p-3">
<Label for="stock-all-matches" class="text-sm font-medium">
Semua sesuai dengan data cutting
</Label>
<Switch id="stock-all-matches" :model-value="allMatches" @update:model-value="setAllMatches" />
</div>
<div class="space-y-2">
<div v-for="(result, index) in verifyForm.results" :key="result.product_variant_id"
class="flex items-center gap-3 rounded-lg border p-3">
@ -196,7 +160,6 @@ function submitVerify() {
class="text-[10px] text-muted-foreground block">Bagus</label>
<Input :id="`stock-good-${index}`" type="number" v-model.number="result.good"
min="0" :max="result.cutting_result" class="h-7 w-16 px-1.5 text-xs text-center"
:disabled="allMatches"
@input="result.reject = result.cutting_result - result.good" />
</div>
<div class="text-center">
@ -204,7 +167,6 @@ function submitVerify() {
class="text-[10px] text-muted-foreground block">Reject</label>
<Input :id="`stock-reject-${index}`" type="number" v-model.number="result.reject"
min="0" :max="result.cutting_result" class="h-7 w-16 px-1.5 text-xs text-center"
:disabled="allMatches"
@input="result.good = result.cutting_result - result.reject" />
</div>
</div>