Skip to content

Commit

Permalink
isValidOptionalUrlを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
mehm8128 committed Jan 8, 2024
1 parent 7820569 commit 8eda3f6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/pages/ContestEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { computed, ref } from 'vue'
import LabeledForm from '/@/components/Form/LabeledForm.vue'
import DeleteForm from '/@/components/Form/DeleteForm.vue'
import FormDuration from '/@/components/UI/FormDuration.vue'
import { isValidDuration, isValidLength, isValidUrl } from '/@/use/validate'
import {
isValidDuration,
isValidLength,
isValidOptionalUrl
} from '/@/use/validate'
import useModal from '/@/components/UI/composables/useModal'
import ConfirmModal from '/@/components/UI/ConfirmModal.vue'
import { useContestStore } from '/@/store/contest'
Expand Down Expand Up @@ -42,7 +46,7 @@ const canSubmit = computed(
!isSending.value &&
isValidLength(formValues.value.name, 1, 32) &&
isValidDuration(formValues.value.duration) &&
(formValues.value.link !== '' ? isValidUrl(formValues.value.link) : true) &&
isValidOptionalUrl(formValues.value.link) &&
isValidLength(formValues.value.description, 1, 256)
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ContestNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import LabeledForm from '/@/components/Form/LabeledForm.vue'
import FormInput from '/@/components/UI/FormInput.vue'
import FormTextArea from '/@/components/UI/FormTextArea.vue'
import FormDuration from '/@/components/UI/FormDuration.vue'
import { isValidDuration, isValidLength, isValidUrl } from '/@/use/validate'
import { isValidDuration, isValidLength, isValidOptionalUrl} from '/@/use/validate'
import { useToast } from 'vue-toastification'
import { useContestStore } from '/@/store/contest'
Expand All @@ -31,7 +31,7 @@ const canSubmit = computed(
() =>
!isSending.value &&
isValidLength(formValues.name, 1, 32) &&
(formValues.link !== '' ? isValidUrl(formValues.link) : true) &&
isValidOptionalUrl(formValues.link) &&
isValidDuration(formValues.duration) &&
isValidLength(formValues.description, 1, 256)
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ContestTeamEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import FormInput from '/@/components/UI/FormInput.vue'
import { computed, ref } from 'vue'
import LabeledForm from '/@/components/Form/LabeledForm.vue'
import DeleteForm from '/@/components/Form/DeleteForm.vue'
import { isValidLength, isValidUrl } from '/@/use/validate'
import { isValidLength, isValidOptionalUrl } from '/@/use/validate'
import useModal from '/@/components/UI/composables/useModal'
import ConfirmModal from '/@/components/UI/ConfirmModal.vue'
import { useToast } from 'vue-toastification'
Expand Down Expand Up @@ -42,7 +42,7 @@ const canSubmit = computed(
!isSending.value &&
isValidLength(formValues.value.name, 1, 32) &&
isValidLength(formValues.value.result, 0, 32) &&
(formValues.value.link !== '' ? isValidUrl(formValues.value.link) : true) &&
isValidOptionalUrl(formValues.value.link) &&
isValidLength(formValues.value.description, 1, 256) &&
members.value.length > 0
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ContestTeamNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import FormTextArea from '/@/components/UI/FormTextArea.vue'
import FormInput from '/@/components/UI/FormInput.vue'
import { computed, ref } from 'vue'
import LabeledForm from '/@/components/Form/LabeledForm.vue'
import { isValidLength, isValidUrl } from '/@/use/validate'
import { isValidLength, isValidOptionalUrl } from '/@/use/validate'
import { useToast } from 'vue-toastification'
import { useUserStore } from '/@/store/user'
Expand All @@ -38,7 +38,7 @@ const canSubmit = computed(
!isSending.value &&
isValidLength(formValues.value.name, 1, 32) &&
isValidLength(formValues.value.result, 0, 32) &&
(formValues.value.link !== '' ? isValidUrl(formValues.value.link) : true) &&
isValidOptionalUrl(formValues.value.link) &&
isValidLength(formValues.value.description, 1, 256) &&
members.value.length > 0
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import LabeledForm from '/@/components/Form/LabeledForm.vue'
import DeleteForm from '/@/components/Form/DeleteForm.vue'
import {
isValidLength,
isValidUrl,
isValidOptionalUrl,
isValidYearWithSemesterDuration
} from '/@/use/validate'
import { useToast } from 'vue-toastification'
Expand Down Expand Up @@ -47,7 +47,7 @@ const canSubmit = computed(
!isSending.value &&
isValidLength(formValues.value.name, 1, 32) &&
isValidYearWithSemesterDuration(formValues.value.duration) &&
(formValues.value.link !== '' ? isValidUrl(formValues.value.link) : true) &&
isValidOptionalUrl(formValues.value.link) &&
isValidLength(formValues.value.description, 1, 256) &&
members.value.every(member =>
isValidYearWithSemesterDuration(member.duration)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ProjectNew.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ProjectMember from '/@/components/Projects/ProjectMember.vue'
import { useUserStore } from '/@/store/user'
import {
isValidLength,
isValidUrl,
isValidOptionalUrl,
isValidYearWithSemesterDuration
} from '/@/use/validate'
import { useProjectStore } from '/@/store/project'
Expand Down Expand Up @@ -69,7 +69,7 @@ const canSubmit = computed(
() =>
!isSending.value &&
isValidLength(formValues.name, 1, 32) &&
(formValues.link !== '' ? isValidUrl(formValues.link) : true) &&
isValidOptionalUrl(formValues.link) &&
isValidYearWithSemesterDuration(formValues.duration) &&
isValidLength(formValues.description, 1, 256) &&
isValidYearWithSemesterDuration(formValues.duration) &&
Expand Down
5 changes: 5 additions & 0 deletions src/use/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export const isValidUrl = (link: string) => {
return url.protocol === 'http:' || url.protocol === 'https:'
}

export const isValidOptionalUrl = (link: string) => {
if (link === '') return true
return isValidUrl(link)
}

export const isValidDuration = (duration: Duration) => {
if (duration.since && duration.until) {
return duration.since <= duration.until
Expand Down

0 comments on commit 8eda3f6

Please sign in to comment.