fix: 条件変更時に有効期限を変更していないのに勝手に更新される問題を修正

This commit is contained in:
Chocolate Pie 2023-06-19 17:01:10 +09:00
parent f1889d3c5b
commit 9b00b3556e
2 changed files with 13 additions and 4 deletions

View File

@ -56,6 +56,7 @@ const props = defineProps<{
expiresAt: string;
forward: boolean;
expirationDate: string;
beforeExpiresAt?: string;
}
editable: boolean;
data?: {
@ -77,9 +78,6 @@ const emit = defineEmits(['update:modelValue']);
const value = computed({
get() {
if (props.modelValue && props.editable) {
emit('update:modelValue', props.data ?? props.modelValue);
}
const data = props.data ?? props.modelValue ?? {
name: '',
targetUserPattern: '',
@ -93,6 +91,9 @@ const value = computed({
data[key] = '';
}
}
if (props.modelValue && props.editable) {
emit('update:modelValue', data);
}
return data as unknown as Exclude<NonNullType<typeof props.modelValue>, undefined>;
},
set(updateValue) {
@ -116,6 +117,11 @@ function renderExpirationDate(empty = false) {
watch(() => value.value.expirationDate, () => renderExpirationDate(), { immediate: true });
watch(() => value.value.expiresAt, () => renderExpirationDate(true));
watch(() => props.editable, () => {
if (props.editable) {
value.value.beforeExpiresAt = value.value.expiresAt;
}
});
</script>
<style lang="scss">

View File

@ -123,6 +123,7 @@ let editingResolver = $ref<{
expiresAt: string;
expirationDate: string;
forward: boolean;
beforeExpiresAt?: string;
}>(defaultResolver);
const pagination = {
@ -155,7 +156,9 @@ function save(): void {
targetUserPattern: editingResolver.targetUserPattern || null,
reporterPattern: editingResolver.reporterPattern || null,
reportContentPattern: editingResolver.reportContentPattern || null,
expiresAt: editingResolver.expiresAt,
...(editingResolver.beforeExpiresAt && editingResolver.beforeExpiresAt === editingResolver.expiresAt ? {} : {
expiresAt: editingResolver.expiresAt,
}),
forward: editingResolver.forward,
}).then(() => {
editableResolver = null;